I have a Person model which have a relationship with a City model:
class Person(models.Model):
...
state = models.CharField(max_length=2, choices=STATES)
city = models.ForeignKey('City')
class PersonForm(ModelForm):
...
class Meta:
model = Person
class City(models.Model):
name = models.CharField(max_length=200)
state = models.CharField(max_length=2)
I am using a ModelForm to render the Person form in the template, through the as_p attribute.
I have a pre-loaded set of data for the City database (it is a huge set of data in the DB), and I don’t wan’t that data to be loaded into a select list in the form created to include Person.
Is there any way to avoid that set of data being loaded in the html, using ModelForm and the as_p attribute?
Thanks in advance!
Ofcourse, you can overwrite any field or any widget, have a look, the django documentation is pretty clear on this:
modelform