how to have "city" fields depending on "country" field in Django models, without creating their tables
<p>I know there are several questions asked like this (such as <a href="http://stackoverflow.com/questions/25706639/django-dependent-select">this one</a>), but non of them could help me with my problem.</p>

<p>I wanna have a City and a Country field in my models, which the City choices is depended on Country; BUT I do not want to define City and Country as models classes. here is my code :</p>

<pre><code>from django.contrib.auth.models import User
from django.db import models
from django.forms import ChoiceField
from django_countries.fields import CountryField


class UserProfile(models.Model):
    user = models.OneToOneField(User, related_name="UserProfile")
    name = models.CharField(max_length=30, null=False, blank=False)
    picture = models.ImageField(upload_to='userProfiles/', null=False, blank=False)
    date_of_birth = models.DateTimeField(null=False, blank=False)
    country = CountryField()
    # city = ??
    national_code = models.IntegerField(max_length=10, null=False, blank=False)
    email = models.EmailField()

    def __str__(self):
        return '{}'.format(self.user.username)

    def __unicode__(self):
        return self.user.username
</code></pre>

<p>just like field "country" which is <code>country = CountryField()</code>, I wonder if there is a way that I could do the mission without defining the <code>class Country(models.Model)</code> or <code>class City(models.Model)</code></p>

<p>the only way for it would be to define choices in your model: </p>

<pre><code>class UserProfile(models.Model):
    CITIES = (
        ('ny', 'New York'),
        ('sm', 'Santa Monica')
        # .. etc
    )
    city = models.CharField(max_length=5, choices=CITIES, blank=True)
</code></pre>

<p><a href="https://docs.djangoproject.com/en/1.10/ref/models/fields/#django.db.models.Field.choices" rel="nofollow">more in the docs</a></p>

python django django-countries