I have a problem with the following (simplified version) models:
Sponsor(models.Model):
sponsor_name = models.CharField()
Concerts(models.Model):
artist_name = models.CharField()
sponsor = models.ManyToMany(Sponsor)
I go to the admin interface and add a new Sponsor, it automatically shows on any concert, all Sponsors show on all Concerts. That is not what I want, I want SOME sponsors to be on SOME concerts.
I realize this is a relationships problem.
I have tried:
Sponsor(models.Model):
belongs_to = models.ForeignKey(Concerts)
sponsor_name = models.CharField()
Concerts(models.Model):
artist_name = models.CharField()
But now I can’t reuse sponsors, I have to add a new one for each Concert.
I think you’re mistaking possible values with actually chosen
SponsorinConcertmodel in django-admin interface.Try this
python manage.py shelland thenfrom yourapp.yourmodel import Concerts; Concerts.objects.sponsor_set.all().Result should contain only selected
Sponsorsfor that model (I bet you’ll see empty list).