Reputation: 1365
I have a field in a class that depends on another field in the same class but I have a problem to code:
class myclass(models.Model):
nation = [('sp', 'spain'), ('fr', 'france')]
nationality = models.CharField(max_length=2, choices=nation)
first_name = models.CharField(max_length=2, choices=name)
I want to put name = [('ro', 'rodrigo'), ('ra', 'raquel')] if nation = spain and name = [('lu', 'luis'), ('ch', 'chantal')] if nation = france.
How I can do that? Thanks!
Upvotes: 0
Views: 68
Reputation: 2131
I think what you want to do is change the view that the user sees. What you have above is the underlying DB model which is the wrong place for this sort of feature.
In addition (assuming this is a web application), you will probably need to do it in Javascript, so you can change the set of allowed names as soon as the user changes the nationality field.
Upvotes: 1