Re: "Legal" way to have foreign key field in the custom form

2008-12-13 Thread Eugene Mirotin

I have only overriden the title and content blocks, nothing more, so
it really looks strange

On Dec 13, 10:04 pm, Jeff FW  wrote:
> Glad to help.
>
> That's strange that you had to add that JS to your template--it should
> be included automatically.  Looking at the admin default 
> options:http://code.djangoproject.com/browser/django/trunk/django/contrib/adm...
> it should be on every object add/edit page.
>
> Maybe you defined a Media class in your admin class? Or you overrode
> the wrong block in your template?  If you're overriding the block
> "extrahead", make sure to put a {{ block.super }} in there, so it
> includes anything that's been defined by parent templates.
>
> -Jeff
>
> On Dec 12, 2:32 pm, Eugene Mirotin  wrote:
>
> > Thank you very much for the help. It have finally solved the problem.
>
> > BTW, one issue was left - the plus icon redirected to the creation
> > page instead of opening popup.
> > I've solved it by including the
> > 
> > directly in my template, but it's strange since my template extends
> > the "admin/change_form.html".
>
> > On Dec 12, 9:05 pm, Jeff FW  wrote:
>
> > > You're passing your queryset in, but you're never using it in your
> > > widget.  In my code, see how I have:
>
> > > widgets.CategorySelect(
> > >     categories=models.Category.objects.order_by('parent',
> > > 'list_order')
> > > ),
>
> > > I don't have the code on hand for my CategorySelect widget, but I
> > > remember that it takes "categories", and turns it into a list of
> > > choices, which then get passed to Select.__init__() as "choices".
> > > Since you're just using a Select() directly, you'd want to pass the
> > > choices in there.  Here's a simple list comprehension that you may
> > > have to adapt a little to do that:
>
> > > [(t.id, unicode(t)) for t in queryset.all()]
>
> > > That assumes that you add "queryset" as an argument to __init__(),
> > > which you should probably do.
>
> > > -Jeff
>
> > > On Dec 12, 1:06 pm, Eugene Mirotin  wrote:
>
> > > > I was busy for several days and could give it a try only now. Thank
> > > > you for the answer, but I still can't make it work.
> > > > I have the model called Tournament and the model called
> > > > TournamentResult which has foreign keys Team and Tournament.
>
> > > > What I'm doing is a page for bulk upload of the results for the
> > > > specific tournament that should be selected from the drop-down
>
> > > > At the moment my code looks like this:
>
> > > > class TournamentChoiceField(forms.ModelChoiceField):
> > > >     def __init__(self, *args, **kwargs):
> > > >         super(TournamentChoiceField, self).__init__(*args, **kwargs)
> > > >         self.widget = admin_widgets.RelatedFieldWidgetWrapper(
> > > >             forms.Select(),
> > > >             TournamentResult._meta.get_field('tournament').rel,
> > > >             admin.site,
> > > >         )
>
> > > > class UploadFormInitial(forms.Form):
> > > >     tournament = TournamentChoiceField(Tournament.objects.all())
>
> > > > But I don't see any values in the drop-down list.
>
> > > > On Dec 9, 3:55 pm, Jeff FW  wrote:
>
> > > > > To get the plus icon back, you need to wrap the field in a
> > > > > RelatedFieldWidgetWrapper.  Here's an example from my code--obviously,
> > > > > you'll have to adapt it to fit your situation.
>
> > > > > class CategoryChoiceField(forms.ModelChoiceField):
>
> > > > >     def __init__(self, *args, **kwargs):
> > > > >         super(CategoryChoiceField, self).__init__(*args, **kwargs)
> > > > >         self.widget = widgets.RelatedFieldWidgetWrapper(
> > > > >             widgets.c(
> > > > >                 categories=models.Category.objects.order_by('parent',
> > > > > 'list_order')),
> > > > >             models.Category._meta.get_field('parent').rel,
> > > > >             admin.site,
> > > > >         )
>
> > > > > -Jeff
>
> > > > > On Dec 9, 6:50 am, Eugene Mirotin  wrote:
>
> > > > > > Well, looks that the ModelChoiceField solves the problem except of 
> > > > > > the
> > > > > > plus icon
>
> > > > > > On Dec 9, 12:34 pm, Eugene Mirotin  wrote:
>
> > > > > > > Hello. I'm working on the custom admin page  that will serve batch
> > > > > > > items creation based on the uploaded file.
> > > > > > > All these items should be linked to the single foreign key item.
> > > > > > > This item should be selected on the form.
> > > > > > > Of course, I can investigate the inner structure of the rendered 
> > > > > > > admin
> > > > > > > pages and mimic it my template, but it doesn't look DRY.
> > > > > > > So I want to {% include %} the fieldset.html and pass the 
> > > > > > > variable to
> > > > > > > it that will make it to render the standard ForeignKey control 
> > > > > > > (with
> > > > > > > "+" icon).
> > > > > > > Is there a legal way to do it?
--~--~-~--~~~---~--~~
You received this 

Re: "Legal" way to have foreign key field in the custom form

2008-12-13 Thread Jeff FW

Glad to help.

That's strange that you had to add that JS to your template--it should
be included automatically.  Looking at the admin default options:
http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/options.py#L202
it should be on every object add/edit page.

Maybe you defined a Media class in your admin class? Or you overrode
the wrong block in your template?  If you're overriding the block
"extrahead", make sure to put a {{ block.super }} in there, so it
includes anything that's been defined by parent templates.

-Jeff

On Dec 12, 2:32 pm, Eugene Mirotin  wrote:
> Thank you very much for the help. It have finally solved the problem.
>
> BTW, one issue was left - the plus icon redirected to the creation
> page instead of opening popup.
> I've solved it by including the
> 
> directly in my template, but it's strange since my template extends
> the "admin/change_form.html".
>
> On Dec 12, 9:05 pm, Jeff FW  wrote:
>
> > You're passing your queryset in, but you're never using it in your
> > widget.  In my code, see how I have:
>
> > widgets.CategorySelect(
> >     categories=models.Category.objects.order_by('parent',
> > 'list_order')
> > ),
>
> > I don't have the code on hand for my CategorySelect widget, but I
> > remember that it takes "categories", and turns it into a list of
> > choices, which then get passed to Select.__init__() as "choices".
> > Since you're just using a Select() directly, you'd want to pass the
> > choices in there.  Here's a simple list comprehension that you may
> > have to adapt a little to do that:
>
> > [(t.id, unicode(t)) for t in queryset.all()]
>
> > That assumes that you add "queryset" as an argument to __init__(),
> > which you should probably do.
>
> > -Jeff
>
> > On Dec 12, 1:06 pm, Eugene Mirotin  wrote:
>
> > > I was busy for several days and could give it a try only now. Thank
> > > you for the answer, but I still can't make it work.
> > > I have the model called Tournament and the model called
> > > TournamentResult which has foreign keys Team and Tournament.
>
> > > What I'm doing is a page for bulk upload of the results for the
> > > specific tournament that should be selected from the drop-down
>
> > > At the moment my code looks like this:
>
> > > class TournamentChoiceField(forms.ModelChoiceField):
> > >     def __init__(self, *args, **kwargs):
> > >         super(TournamentChoiceField, self).__init__(*args, **kwargs)
> > >         self.widget = admin_widgets.RelatedFieldWidgetWrapper(
> > >             forms.Select(),
> > >             TournamentResult._meta.get_field('tournament').rel,
> > >             admin.site,
> > >         )
>
> > > class UploadFormInitial(forms.Form):
> > >     tournament = TournamentChoiceField(Tournament.objects.all())
>
> > > But I don't see any values in the drop-down list.
>
> > > On Dec 9, 3:55 pm, Jeff FW  wrote:
>
> > > > To get the plus icon back, you need to wrap the field in a
> > > > RelatedFieldWidgetWrapper.  Here's an example from my code--obviously,
> > > > you'll have to adapt it to fit your situation.
>
> > > > class CategoryChoiceField(forms.ModelChoiceField):
>
> > > >     def __init__(self, *args, **kwargs):
> > > >         super(CategoryChoiceField, self).__init__(*args, **kwargs)
> > > >         self.widget = widgets.RelatedFieldWidgetWrapper(
> > > >             widgets.c(
> > > >                 categories=models.Category.objects.order_by('parent',
> > > > 'list_order')),
> > > >             models.Category._meta.get_field('parent').rel,
> > > >             admin.site,
> > > >         )
>
> > > > -Jeff
>
> > > > On Dec 9, 6:50 am, Eugene Mirotin  wrote:
>
> > > > > Well, looks that the ModelChoiceField solves the problem except of the
> > > > > plus icon
>
> > > > > On Dec 9, 12:34 pm, Eugene Mirotin  wrote:
>
> > > > > > Hello. I'm working on the custom admin page  that will serve batch
> > > > > > items creation based on the uploaded file.
> > > > > > All these items should be linked to the single foreign key item.
> > > > > > This item should be selected on the form.
> > > > > > Of course, I can investigate the inner structure of the rendered 
> > > > > > admin
> > > > > > pages and mimic it my template, but it doesn't look DRY.
> > > > > > So I want to {% include %} the fieldset.html and pass the variable 
> > > > > > to
> > > > > > it that will make it to render the standard ForeignKey control (with
> > > > > > "+" icon).
> > > > > > Is there a legal way to do it?
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en

Re: "Legal" way to have foreign key field in the custom form

2008-12-12 Thread Jeff FW

You're passing your queryset in, but you're never using it in your
widget.  In my code, see how I have:

widgets.CategorySelect(
categories=models.Category.objects.order_by('parent',
'list_order')
),

I don't have the code on hand for my CategorySelect widget, but I
remember that it takes "categories", and turns it into a list of
choices, which then get passed to Select.__init__() as "choices".
Since you're just using a Select() directly, you'd want to pass the
choices in there.  Here's a simple list comprehension that you may
have to adapt a little to do that:

[(t.id, unicode(t)) for t in queryset.all()]

That assumes that you add "queryset" as an argument to __init__(),
which you should probably do.

-Jeff

On Dec 12, 1:06 pm, Eugene Mirotin  wrote:
> I was busy for several days and could give it a try only now. Thank
> you for the answer, but I still can't make it work.
> I have the model called Tournament and the model called
> TournamentResult which has foreign keys Team and Tournament.
>
> What I'm doing is a page for bulk upload of the results for the
> specific tournament that should be selected from the drop-down
>
> At the moment my code looks like this:
>
> class TournamentChoiceField(forms.ModelChoiceField):
>     def __init__(self, *args, **kwargs):
>         super(TournamentChoiceField, self).__init__(*args, **kwargs)
>         self.widget = admin_widgets.RelatedFieldWidgetWrapper(
>             forms.Select(),
>             TournamentResult._meta.get_field('tournament').rel,
>             admin.site,
>         )
>
> class UploadFormInitial(forms.Form):
>     tournament = TournamentChoiceField(Tournament.objects.all())
>
> But I don't see any values in the drop-down list.
>
> On Dec 9, 3:55 pm, Jeff FW  wrote:
>
> > To get the plus icon back, you need to wrap the field in a
> > RelatedFieldWidgetWrapper.  Here's an example from my code--obviously,
> > you'll have to adapt it to fit your situation.
>
> > class CategoryChoiceField(forms.ModelChoiceField):
>
> >     def __init__(self, *args, **kwargs):
> >         super(CategoryChoiceField, self).__init__(*args, **kwargs)
> >         self.widget = widgets.RelatedFieldWidgetWrapper(
> >             widgets.c(
> >                 categories=models.Category.objects.order_by('parent',
> > 'list_order')),
> >             models.Category._meta.get_field('parent').rel,
> >             admin.site,
> >         )
>
> > -Jeff
>
> > On Dec 9, 6:50 am, Eugene Mirotin  wrote:
>
> > > Well, looks that the ModelChoiceField solves the problem except of the
> > > plus icon
>
> > > On Dec 9, 12:34 pm, Eugene Mirotin  wrote:
>
> > > > Hello. I'm working on the custom admin page  that will serve batch
> > > > items creation based on the uploaded file.
> > > > All these items should be linked to the single foreign key item.
> > > > This item should be selected on the form.
> > > > Of course, I can investigate the inner structure of the rendered admin
> > > > pages and mimic it my template, but it doesn't look DRY.
> > > > So I want to {% include %} the fieldset.html and pass the variable to
> > > > it that will make it to render the standard ForeignKey control (with
> > > > "+" icon).
> > > > Is there a legal way to do it?
>
>
--~--~-~--~~~---~--~~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: "Legal" way to have foreign key field in the custom form

2008-12-09 Thread Jeff FW

To get the plus icon back, you need to wrap the field in a
RelatedFieldWidgetWrapper.  Here's an example from my code--obviously,
you'll have to adapt it to fit your situation.

class CategoryChoiceField(forms.ModelChoiceField):

def __init__(self, *args, **kwargs):
super(CategoryChoiceField, self).__init__(*args, **kwargs)
self.widget = widgets.RelatedFieldWidgetWrapper(
widgets.CategorySelect(
categories=models.Category.objects.order_by('parent',
'list_order')),
models.Category._meta.get_field('parent').rel,
admin.site,
)

-Jeff

On Dec 9, 6:50 am, Eugene Mirotin <[EMAIL PROTECTED]> wrote:
> Well, looks that the ModelChoiceField solves the problem except of the
> plus icon
>
> On Dec 9, 12:34 pm, Eugene Mirotin <[EMAIL PROTECTED]> wrote:
>
> > Hello. I'm working on the custom admin page  that will serve batch
> > items creation based on the uploaded file.
> > All these items should be linked to the single foreign key item.
> > This item should be selected on the form.
> > Of course, I can investigate the inner structure of the rendered admin
> > pages and mimic it my template, but it doesn't look DRY.
> > So I want to {% include %} the fieldset.html and pass the variable to
> > it that will make it to render the standard ForeignKey control (with
> > "+" icon).
> > Is there a legal way to do it?
>
>
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: "Legal" way to have foreign key field in the custom form

2008-12-09 Thread Eugene Mirotin

Well, looks that the ModelChoiceField solves the problem except of the
plus icon

On Dec 9, 12:34 pm, Eugene Mirotin <[EMAIL PROTECTED]> wrote:
> Hello. I'm working on the custom admin page  that will serve batch
> items creation based on the uploaded file.
> All these items should be linked to the single foreign key item.
> This item should be selected on the form.
> Of course, I can investigate the inner structure of the rendered admin
> pages and mimic it my template, but it doesn't look DRY.
> So I want to {% include %} the fieldset.html and pass the variable to
> it that will make it to render the standard ForeignKey control (with
> "+" icon).
> Is there a legal way to do it?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



"Legal" way to have foreign key field in the custom form

2008-12-09 Thread Eugene Mirotin

Hello. I'm working on the custom admin page  that will serve batch
items creation based on the uploaded file.
All these items should be linked to the single foreign key item.
This item should be selected on the form.
Of course, I can investigate the inner structure of the rendered admin
pages and mimic it my template, but it doesn't look DRY.
So I want to {% include %} the fieldset.html and pass the variable to
it that will make it to render the standard ForeignKey control (with
"+" icon).
Is there a legal way to do it?

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---