Skip to content

Instantly share code, notes, and snippets.

import tempfile
from itertools import chain
from django.contrib import admin
from django.contrib.admin.utils import NestedObjects
from django.core import serializers
from django.http import HttpResponse
from example_app.models import *
from django.db import models
class PersonManager(models.Manager):
def get_by_natural_key(self, first_name, last_name):
return self.get(first_name=first_name, last_name=last_name)
class Person(models.Model):
first_name = models.CharField(max_length=100)
import tempfile
from itertools import chain
from django.contrib import admin
from django.contrib.admin.utils import NestedObjects
from django.core import serializers
from django.http import HttpResponse
from example_app.models import *
import tempfile
from django.contrib import admin
from django.core import serializers
from django.http import HttpResponse
from example_app.models import *
@admin.action(description="Export Model")
from django.contrib import admin
from example_app.models import *
class PersonAdmin(admin.ModelAdmin):
pass
admin.site.register(Person, PersonAdmin)
from django.db import models
class Person(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
class Book(models.Model):
name = models.CharField(max_length=100)
from django.core import serializers
data = serializers.serialize("json", SomeModel.objects.all())