anyone?

On Aug 26, 12:19 pm, patrickk <[EMAIL PROTECTED]> wrote:
> scenario: users are uploading documents (e.g. images, files, ...).
> these documents are saved in a model "Attachment" assigned to the
> currently logged-in "User". now, every user has the possibility to
> attach documents to a blog-entry. these attachments are saved in a
> model "BlogEntryAttachment" assigned to a "BlogEntry".
> the best way to achieve this is probably using formsets. when writing
> a BlogEntry, the user has the option to attach his/her documents to
> that BlogEntry. to achieve this, I have to limit the choices (of a
> select-field) to the currenlty logged-in User.
>
> questions & notes:
> ### how can I limit the choices of a select-field using formsets?
> ### I've tried inlineformset_factory, but there's no argument
> "initial". besides that, I´m not sure how to use "initial" for
> limiting a queryset ...
> ### with using formset_factory on the other hand, I could use a
> ModelChoiceField with queryset=Attachment.objects.filter(user=user),
> but how do I get the "user" there?
> ### Overriding __init__ within BlogEntryAttachmentForm and passing the
> currently logged-in user seems possible, but then I also have to
> override the BaseFormSets __init__ and _construct_form, which just
> seems ugly and far too complicated.
>
> MODELS:
>
> class Attachment(models.Model):
>
>     user = models.ForeignKey('auth.User')
>     title = models.CharField('Title', max_length=100, blank=True,
> null=True)
>     filename = models.CharField('Filename', max_length=100,
> blank=True, null=True)
>     path = models.CharField('Path', max_length=200, blank=True,
> null=True)
>     ...
>
> class BlogEntryAttachment(models.Model):
>
>     blogentry = models.ForeignKey(BlogEntry)
>     attachment = models.ForeignKey(Attachment)
>     ....
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to