2👍
✅
You are describing a many-to-one relationship. This should be modeled by an extra Model
having a CharField
to store the string and ForeignKey
to your main Model
(as @Kujira has already pointed out):
class YourModel(models.Model):
pass
class String(models.Model):
your_model = models.ForeignKey('YourModel', related_name='strings')
string = models.CharField('String', max_len=..., ...)
Now you can add strings to an instance of YourModel
:
ym = YourModel.objects.create()
ym.strings.create(string='string1')
ym.strings.create(string='string2')
- [Answered ]-Django use Case When to compose sql query
- [Answered ]-Getting how the view was called with HttpRedirect in the next view
- [Answered ]-Django: Correct way to save HTML code inside database
- [Answered ]-Django: Create check boxes dynamically based on select dropdown with Jquery/Ajax?
Source:stackexchange.com