I have one application and one model. I want to separate the model on two applications, so that the user was managed from a separate application. Is the transfer of this model will do the trick? What I have to do?
class User(AbstractUser):
country = models.CharField(max_length=2, choices=COUNTRY, default=RUSSIA)
Here is my models.py - must be separate
RUSSIA = 'RUS'
USA = 'USA'
GERMANY = 'GER'
COUNTRY = (
(RUSSIA, "Russia"),
(USA, "USA"),
(GERMANY, "Germany"),
)
class User(AbstractUser):
country = models.CharField(max_length=2, choices=COUNTRY, default=RUSSIA)
class Country(models.Model):
country = models.CharField(max_length=3, choices=COUNTRY, default=RUSSIA)
name_of_team = models.CharField(max_length=255, blank=True, null=True)
def __unicode__(self):
return self.name_of_team
You can create two applications, one for Users and one for Countries. Then put the User model in the Users app and the Country model in the Countries app.
Then in a third app you can import both as you need them:
from countries.models import Country
from users.models import User
Put this part of the code in the settings.py file:
RUSSIA = 'RUS'
USA = 'USA'
GERMANY = 'GER'
COUNTRY = (
(RUSSIA, "Russia"),
(USA, "USA"),
(GERMANY, "Germany"),
)
If you do this then you can access the constants from both apps like this:
from django.conf import settings
settings.COUNTRY