I've made a protocol model with attachments and comments
(see below)
The idea is that you can add an arbitrary number of attachment
in the protocol part of the admin interface
if I open a new protocol admin page there a section with
Attachment #1
Document: [empty-text-box] [browse-button]
I browse to a file and press 'Save and continue editing'
then the attachement shows up at attachment #1
and there's a attachment #2 section
Attachment #1
Document: Currently: protocols/file1.pdb
Change:
Attachment #2
Document:
Now if I browse to a second file and press 'Save and continue editing'
again, my first file gets replaced by the second, so I see.
Attachment #1
Document: Currently: protocols/file2.pdb
Change:
Attachment #2
Document:
and file1 is even gone from the opload dir.
what am I doing wrong???
-abe
from django.db import models
import datetime
class Protocol(models.Model):
title = models.CharField(maxlength=600,blank=True)
author = models.CharField(maxlength=600,blank=True)
category = models.CharField(maxlength=600,blank=True)
version = models.CharField(maxlength=100,default='1.0',blank=True)
text = models.TextField(maxlength=6000,blank=True)
submission_date = models.DateTimeField('date
submitted',auto_now_add=True,null=True)
modification_date = models.DateTimeField('date
modified',auto_now=True,null=True)
class Admin:
list_display =
('title','version','category','submission_date','modification_date')
search_fields = ('category','title')
fields = (
(None, {'fields': (
('title','version','author'),
('category'),
('text'),
)}
),
('Date information', {'fields': (
('submission_date','modification_date'),
), 'classes': 'collapse'}
),
)
save_as=True
save_on_top=True
class Meta:
pass
def __repr__(self):
return "'%s %s v%s"%(self.category,self.title,self.version)
#def count_comments(self):
# return len(self.objects.all())
class Comment(models.Model):
protocol = models.ForeignKey(Protocol,edit_inline=models.TABULAR,
num_in_admin=1,num_extra_on_change=1)
title = models.CharField(maxlength=600,blank=True,core=True)
author = models.CharField(maxlength=600,blank=True,core=True)
text=models.TextField(maxlength=6000,blank=True,core=True)
class Admin:
pass
class Meta:
pass
def __repr__(self):
return self.title
class Attachment(models.Model):
protocol = models.ForeignKey(Protocol,edit_inline=models.STACKED,
num_in_admin=1,num_extra_on_change=1)
document = models.FileField(upload_to='protocols/',core=True)
class Admin:
fields = (
(None, {'fields': (
('protocol','document'),
)}
),
)
pass
class Meta:
pass
def __repr__(self):
return '%s: %s'%(self.protocol,self.document)