This might be a simple Django question, but I hope I can get som advice. The following code in admin.py
class ExarbeteMomentInline(admin.TabularInline):
model = ExarbeteMoment
extra=0
class ExarbeteStudent(admin.TabularInline):
model = ExarbeteStudent
extra=0
class ExamensarbeteAdmin(admin.ModelAdmin):
list_display = ('title', 'start_date', 'end_date', 'company')
inlines = [ExarbeteMomentInline, ExarbeteStudent]
admin.site.register(Examensarbete,ExamensarbeteAdmin)
produces what I want, in the admin panel.
But I want a version of it outside the admin panel, so that regular users can enter data. How can I modify the code in a minimal way to get essentially the same page outside the admin region?
Thanks, in advance.
/ADDED/ My models are:
class Examensarbete(models.Model):
title = models.CharField(max_length=10000,default='',blank=True)
start_date = models.DateField('startdatum')
end_date = models.DateField('slutdatum',blank=True,default='',null=True)
company = models.CharField(max_length=200,default='',blank=True)
comment = models.TextField(max_length=1000,default='',blank=True)
kurskod = models.CharField(max_length=100,default='FMAM05')
year = models.CharField(max_length=5,blank=True,default='',null=True)
class ExarbeteMoment(models.Model):
exarbete = models.ForeignKey(Examensarbete,on_delete=models.CASCADE)
typ = models.CharField(max_length=100)
person = models.ForeignKey(Personal,on_delete=models.SET_NULL,null=True)
tim = models.FloatField(null=True)
class ExarbeteStudent(models.Model):
exarbete = models.ForeignKey(Examensarbete,on_delete=models.CASCADE)
first_name=models.CharField(max_length=100)
last_name=models.CharField(max_length=100)
pnr = models.CharField(max_length=13)
program = models.CharField(max_length=5)
kull = models.CharField(max_length=5)
where I have deleted str and Meta. I guess I should be able to solve the problem with the help below, but I can't still figure out how I get what I get in the admin panel, with Examensarbete above and then two subforms with ExarbeteMoment and ExarbeteStudent. And the 'add another item' feature.
Unfortunately I am new to Django, and find it particularly hard to work with forms and formsets. I am not quite sure why, because they should simplify things considerably.