In the app I'm building some users have the role "Coder" and are assigned to "Assignments".
What I can't seem to get working is the process of an Admin assigning Coders to Assignments.
Here is the Model-Code I have so far (probably totally wrong):
class Coder(models.Model):
"""Every user can be a coder. Coders are assigned to Assignments"""
user = models.OneToOneField(User)
class Admin:
list_display = ('',)
search_fields = ('',)
def __unicode__(self):
return u"Coders"
class Assignment(models.Model):
"""(Assignment description)"""
title = models.CharField(blank=True, max_length=100)
start_year = models.IntegerField(blank=True, null=True)
end_year = models.IntegerField(blank=True, null=True)
country = models.IntegerField(blank=True, null=True)
coders = models.ManyToManyField(Coder)
class Admin:
list_display = ('',)
search_fields = ('',)
def __unicode__(self):
return u"Assignment"
And this is the admin-code:
class AssignmentCoderInline(admin.StackedInline):
model = Assignment.coders.through
can_delete = False
verbose_name_plural = 'coder'
class AssignmentAdmin(admin.ModelAdmin):
fieldsets = [
('Assignment', {'fields': ['title', 'start_year', 'end_year']})
]
inlines = (AssignmentCoderInline,)
class CoderInline(admin.StackedInline):
model = Coder
can_delete = False
verbose_name_plural = 'coder'
Now, when i'm in the admin, I want to create an assignment and add coders to it.
Yet all I see when trying to do so is this:
How can I add one coder/user to an assignment, so I can later show him in a view all the assignments he has? This is probably a really dumb question, but please answer anyways, I greatly appreciate any help :)