Adding related tables to custom Users table
This issue is to be performed after #5 is finished.
Description
Create a new model inside users app which is named as UserAddress. It is self explanatory what this model will contain. For now , just create the following fields:
country
city
state
All three of these fields are Foreign Keys from other tables. That means you will also need to create three more tables:
Country
id
title
three letter country code as "code"
City
id
title
city code as "code"
State
id
title
city code as "code"
📌 Note: You can use migrations as seeders to populate the Country, City and State. Learn more about this from this stackoverflow post.
As for JSON data of the countries, cities annd states, can be generated using online tools.
References
NOTE: This is a reference code, DO NOT use it as is.
class Country(models.Model):
title = models.CharField(_("Title"), max_length=255)
code = models.CharField(_("Code"), max_length=255)
class Meta:
verbose_name_plural = "Countries"
def __str__(self) -> str:
return self.title
class State(models.Model):
title = models.CharField(_("Title"), max_length=255)
country = models.ForeignKey(Country, related_name='state_country', on_delete=models.SET_NULL, null=True)
def __str__(self) -> str:
return self.title
class City(models.Model):
title = models.CharField(_("Title"), max_length=255)
state = models.ForeignKey(State, related_name='city_state', on_delete=models.SET_NULL, null=True)
class Meta:
verbose_name_plural = "Cities"
def __str__(self) -> str:
return self.title
Scope
Adding related tables to custom Users table This issue is to be performed after #5 is finished.
Description
Create a new model inside
users
app which is named asUserAddress
. It is self explanatory what this model will contain. For now , just create the following fields:All three of these fields are Foreign Keys from other tables. That means you will also need to create three more tables:
References