Skip to content

Instantly share code, notes, and snippets.

from django.core import serializers
data = serializers.serialize("json", SomeModel.objects.all())
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.contrib import admin
from example_app.models import *
class PersonAdmin(admin.ModelAdmin):
pass
admin.site.register(Person, PersonAdmin)
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")
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 *