Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I have this model:

class Artist(models.Model):
    name = models.CharField(max_length=50)
    pseudo = models.CharField(max_length=50)
    birth_date = models.DateField()
    country = models.CharField(max_length=50)
    instruments = models.CharField(max_length=50)
    genre = models.CharField()
    active = models.DateField()
    labels = models.CharField(max_length=255)
    website = models.URLField()

but some fields are optional (pseudo, instruments). How to solve the problem of optionality of the fields? I can add blank=True to this fields:

class Artist(models.Model):
    name = models.CharField(max_length=50)
    pseudo = models.CharField(max_length=50, blank=True)
    birth_date = models.DateField()
    country = models.CharField(max_length=50)
    instruments = models.CharField(max_length=50, blank=True)
    genre = models.CharField()
    active = models.DateField()
    labels = models.CharField(max_length=255)
    website = models.URLField()

and do not enter data, but maybe you know a better solution?

share|improve this question
1  
Better how? What's wrong with leaving them blank? – Daniel Roseman Nov 9 '12 at 9:53
I don't know, I thought it was bad practice. Ok, I leave these fields blank. Thanks :) – sagem_tetra Nov 9 '12 at 9:59
You could create a separate model with a OneToOneField if you don't like blank fields (but do like added complexity and overhead) – Jesse the Game Nov 10 '12 at 7:50

migrated from stackoverflow.com Nov 12 '12 at 15:02

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.