我正在尝试在django管理面板中的用户模型中输入数据。我希望能够在选择国家时过滤django管理面板中的城市。以下是我的代码。我想我必须在admin.py文件中写一些东西,但我不知道从哪里开始
models.py
from django.db import models
# Create your models here.
class User(models.Model):
name = models.CharField(max_length=100)
country = models.ForeignKey('Country')
city = models.ForeignKey('City')
def __unicode__(self):
return self.name
class Country(models.Model):
country = models.CharField(max_length=100)
def __unicode__(self):
return self.country
class City(models.Model):
city = models.CharField(max_length=100)
country = models.ForeignKey('Country')
def __unicode__(self):
return self.city
admin.py
from django.contrib import admin
from third.models import User, Country, City
# Register your models here.
admin.site.register(City)
admin.site.register(Country)
admin.site.register(User)