Here is a tutorial for adding a plus sign for custom dropdown box in custom admin pages
If you registered your models with adminCreate a widgets.py and put the following code there from django.template.loader import render_to_string from ivl.views import * def SelectWidgetWithPopUp(url): class SelectWithPopUp(forms.Select): def render(self, name, *args, **kwargs): html = super(SelectWithPopUp, self).render(name, *args, **kwargs) popupplus = render_to_string(url, {'field': name}) return html+popupplus return SelectWithPopUp url will be the link where it will open a popup for adding new data. now create the following html file anywhere in your template dir. href location is where my tblpeople model is and I am pointing the "add" view. Now in the admin.py #Import the widget from yourapp.widgets import SelectWidgetWithPopUp #This is the form I will use for people dropdownlist class PeopleForm(forms.Form): peopleid=forms.ModelChoiceField(label='Authors',queryset=Tblpeople.objects, widget=SelectWidgetWithPopUp("people_popup_plus.html")) people_popup_plus.html is the url for pop up. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Please help me make a SELECT box!
Why dont you use a widget with charfield forms.CharField(max_length=1, widget=forms.Select (choices=CHOICES)) and your choices are CHOICE = ( ('A', 'A'), ('B', 'B'), ('C', 'C'), ) On Apr 19, 4:56 pm, amyhalfwrote: > For the life of me I can't get Django to render even the simplest of > HTML boxes. > > Here's a recent example that I have which I cannot get to work. > > This is the form: > > class CreditCardForm(forms.Form): > fullname = forms.CharField(128, 1, required = True) > mm_expiry = forms.ChoiceField(required = True) > > In the view, I do the following before sending it to the template: > > form = CreditCardForm() > form.mm_expiry.choices = (('1','1'), ('2','2')) > > Here's how I print it in the template: > > Expiration date: > {{ form.mm_expiry }} > > It does make the tag but will not populate the individual > items. > > Help! > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
How to set the size for Inline Dropdown lists
Hi I have an inline model. It lists the foreign keys in a dropdown list. It adjusts its size according to the largest text in it. How can I have a small dropdown list? It is too big. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Dynamic Inline fileds
Hi Asim :) Here is the solution step by step: 1) Go to Lib\site-packages\django\contrib\admin\media\js directory and copy the following js files to js folder jquery-1.4.2 from jquery website dynamic_inlines_with_sort.js from http://www.djangosnippets.org/snippets/1489/ and create the following css under css folder dyynamic_inlines_with_sort.css: .inline-group .tabular tr.has_original td { padding-top:0.5em; } .inline-group .tabular tr.has_original td.original p { display:none; } 2)Add following media class to your inline admin model class Media: js = ['/media/js/jquery-1.4.2.js', '/media/js/dynamic_inlines_with_sort.js',] css = { 'all' : ['/media/css/dynamic_inlines_with_sort.css'],} You will see a plus sign or add new row text below. I was able to duplicate text fields,dropdown lists successfully. On 8 Nisan, 13:46, Asim Yuksel <a.sinanyuk...@gmail.com> wrote: > How can I add dynamic inline fields? I want to use the extra=1 and I > want to have a plus sign which will add more dynamic fields so the > extra field will increase -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Dynamic Inline fileds
How can I add dynamic inline fields? I want to use the extra=1 and I want to have a plus sign which will add more dynamic fields so the extra field will increase -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
ModelMultipleChoiceField and plus sign
I have a field called peopleid. The default admin page displays this as a dropdown list and shows a green plus sign near it. Instead of dropdown, I want to use MultipleChoiceField. But if I define this field. I dont see the plus sign? How can I make it appear near the ModelMultipleChoiceField? Here is the form field I am using peopleid = forms.ModelMultipleChoiceField(label='Authors',queryset=Tblpeople.objects.all()) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
2 Views In One Admin Template
How can show two different views in one admin view(change_form.html)? I have a custom change_form.html for a model view. In that model's view, I want to include another view I tried the following but it shows same view again {% for fieldset in adminform %} {% include "admin/includes/Brdgauthorseditors/ authors_editors_fieldset.html" %} {% endfor %} {% for fieldset in adminform %} {% include "admin/includes/Brdgmediapublications/ media_publications_fieldset.html" %} {% endfor %} I understand the reason why it shows the same view. Because it is accessing the current model's adminform. How can I access another view's adminform? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: How to display other field(not the foreign key) in admin dropdown list
Okey I want to answer this :) just add a unicode method to your model something like this def __unicode__(self): return "%s" % self.name On 31 Mart, 16:37, Asim Yuksel <a.sinanyuk...@gmail.com> wrote: > I have a people table and a bridge table which are related. bridge > table has a foreignkey field for people table. > > When I click add from django admin it shows the peopleid in a drop > down list. What I want to do is I want to show the people.name field > instead of peopleid foreignkey field? How can I do this? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Displaying the fields of two tables on the same admin page
The people and publication are not related so I cant use manytomany On 31 Mart, 15:30, "Giovannetti, Mark"wrote: > > I am entering them on the same page otherwise I will have to note down > > the ids of people and publications table and then go to bridge table > > and insert the ids there. So the reason I want to enter in the same > > page is I will insert the ids into bridge table whenever I click save. > > I am not allowed to change the db design by the way and it sucks :) > > Does this not work the way you expect? > > class People(models.Model): > > other fields > > publications = models.ManyToManyField('Publication', > through='PeoplePublication', > ) > > class Publication(models.Model): > > other fields > > class PeoplePublication(models.Model): > > people = models.ForeignKey('People',...) > publication = models.ForeignKey('Publication',...) > > in admin.py: > > class PublicationInline(admin.TabularInline): > model = PeoplePublication > extra = 1 > > class PeopleAdmin(admin.ModelAdmin): > inlines = [PublicationInline] > > admin.site.register(People, PeopleAdmin) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
How to display other field(not the foreign key) in admin dropdown list
I have a people table and a bridge table which are related. bridge table has a foreignkey field for people table. When I click add from django admin it shows the peopleid in a drop down list. What I want to do is I want to show the people.name field instead of peopleid foreignkey field? How can I do this? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Admin Add Page
Thanks but I get error when I try to extend it it says:Caught an exception while rendering: opts and it highlights {% submit_row %} Any ideas? On 31 Mart, 11:23, Brandon Taylor <btaylordes...@gmail.com> wrote: > You can extend the change_form.html and change_list.html templates for > those views, or the base_site.html template. > > Look in your: django/contrib/admin/templates/admin/ folder to see all > of the templates. Also, check out the documentation > at:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-vs... > > Cheers, > Brandon > > On Mar 30, 1:16 pm, Asim Yuksel <a.sinanyuk...@gmail.com> wrote: > > > I want to use a custom admin add page with custom admin look and feel. > > What is the template to extend? I want to use something like this > > >http://picasaweb.google.com/110428031719333287170/BaslKsZAlbum#545448... > > > I tried to hack the html by viewing the source but it is time > > consuming and it always show a message "This field is required.". I > > want to show this message when I click save. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Admin Add Page
I want to use a custom admin add page with custom admin look and feel. What is the template to extend? I want to use something like this http://picasaweb.google.com/110428031719333287170/BaslKsZAlbum#5454485792741726834 I tried to hack the html by viewing the source but it is time consuming and it always show a message "This field is required.". I want to show this message when I click save. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Displaying the fields of two tables on the same admin page
I am entering them on the same page otherwise I will have to note down the ids of people and publications table and then go to bridge table and insert the ids there. So the reason I want to enter in the same page is I will insert the ids into bridge table whenever I click save. I am not allowed to change the db design by the way and it sucks :) On 29 Mart, 06:49, "pjrhar...@gmail.com"wrote: > > I cant use inlines option ind admin,py because the > > tables should be related. > > If they aren't related why would you want to be entering them on the > same page? > > When you come to edit them again what two instances should be loaded > together if they are completely unrelated? > > Given what you first said: > > > 2) I also want to insert the id values of people and publication to a > > bridge table(lets say PeoplePublication) whenever I do the first step. > > you want a ManyToManyField and Inlines. A ManyToManyField > automatically sets up this bridge table. If you want more information > associated with the relationship, look into the "through" option. > > http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.mod... > > Peter -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
How to customize admin's save button functionality?
How can I edit admin's save button, so whenever I click save, I can be redirected to a page after successfully inserting the values into db? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: Displaying the fields of two tables on the same admin page
Sorry for not making it clear. The idea is to use default admin template and help the admin to enter data from admin interface. I will enter data via admin's default template. Lets say I have People and Publications Table in my database. So when I click admin's add button, it will display some fields to enter data for People and Publication Tables. When I click save, the data will be saved to People and Publications table. People and Publications are not related. They are different tables. I cant use inlines option ind admin,py because the tables should be related. On 28 Mart, 15:37, Gramware <dmb...@gmail.com> wrote: > On Mar 28, 8:40 pm, Asim Yuksel <a.sinanyuk...@gmail.com> wrote: > > > I have two questions. > > 1)I have two tables(People, Publication) and they are not related and > > I want to display the fields of these tables on the same admin page. > > So when I fill all the fields, I want to insert these values into > > people and publication tables. > > I do not fully understand your question, but if you would like to > Iterate (loop over) 2 values in your template at the same time, you > can use the zip command like blow > > In your views.py > > peo = People.objects.all() > pub=Publications.objects.all() > > render_to_response(template.html, {'tables':zip(peo,pub)}) > > in your template (template.html) > > {% for pe, pu in tables %} > {{pe.field1}} {{pu.field1}} > {% endfor %} > > I am assuming that for each record in people, there is a matching one > in publications > > > 2) I also want to insert the id values of people and publication to a > > bridge table(lets say PeoplePublication) whenever I do the first step. > > > I guess I cant do the 1st one with inlines. How can I do this? > > Why not use a ForeignKey? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
Displaying the fields of two tables on the same admin page
I have two questions. 1)I have two tables(People, Publication) and they are not related and I want to display the fields of these tables on the same admin page. So when I fill all the fields, I want to insert these values into people and publication tables. 2) I also want to insert the id values of people and publication to a bridge table(lets say PeoplePublication) whenever I do the first step. I guess I cant do the 1st one with inlines. How can I do this? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: ForeignKeyField
You know what I am trying to solve this for about 2 days. Thank you so much it worked :) All my respects to your brain :) On 26 Mart, 20:04, Karen Tracey <kmtra...@gmail.com> wrote: > On Fri, Mar 26, 2010 at 8:00 PM, Asim Yuksel <a.sinanyuk...@gmail.com>wrote: > > > I've tried this. > > The model is > > > class Advisors(models.Model): > > advisorid = models.IntegerField(primary_key=True, > > db_column='advisorId') # Field name made lowercase. > > maphdid = models.ForeignKey(Tblmaphds, db_column='maPhDId') # > > Field name made lowercase. > > rank = models.SmallIntegerField() > > def __unicode__(self): > > return self.maphdid > > class Meta: > > db_table = u'Advisors' > > You are showing a __unicode__ method for the Advisors model. A ForeignKey > field where the related model is a Tblmaphds will use the __unicode__ method > of the Tblmaphds model to display the value of the related field. You need > to add a __unicode__ method to the Tblmaphds model. > > Karen -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: ForeignKeyField
I've tried this. The model is class Advisors(models.Model): advisorid = models.IntegerField(primary_key=True, db_column='advisorId') # Field name made lowercase. maphdid = models.ForeignKey(Tblmaphds, db_column='maPhDId') # Field name made lowercase. rank = models.SmallIntegerField() def __unicode__(self): return self.maphdid class Meta: db_table = u'Advisors' in admin.py I have def AdvisorAdmin(model): class BrdgadvisorsAdmin(admin.ModelAdmin): model = Brdgadvisors list_display = [f.name for f in model._meta.fields] return BrdgadvisorsAdmin admin.site.register(Brdgadvisors,AdvisorAdmin(Brdgadvisors)) So this doesnt work. On 26 Mart, 19:10, Karen Tracey <kmtra...@gmail.com> wrote: > On Fri, Mar 26, 2010 at 4:31 PM, Asim Yuksel <a.sinanyuk...@gmail.com>wrote: > > > here is the list display > > >http://picasaweb.google.com/110428031719333287170/BaslKsZAlbum#545304... > > > I want that to appear in a list display, because that is what the > > client wants :) > > > I tried writing unicode method , but it has no effect.I dont know > > why. > > Since you haven't shown exactly what you tried there, we don't know either. > As documented here: > > http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contri... > > if the field is a ForeignKey, Django will display the __unicode__() of the > related object. > > Thus if your Tblmaphds model had a __unicode__ method, whatever it returned > would be what you see instead of "Tblmaphds object" in list display. > > Adding a __unicode__ method to that model is the easiest way to accomplish > what you are asking for. There are also other options, as noted in that doc > you can define callables on your model or model admin that return whatever > you'd like to be shown in the list display, but really the easiest thing > here would be the __unicode__ method on that model, so I'd suggest you try > to figure out why that easiest solution isn't working before trying other > more complicated things. > > Karen -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: ForeignKeyField
here is the list display http://picasaweb.google.com/110428031719333287170/BaslKsZAlbum#5453042316004332754 I want that to appear in a list display, because that is what the client wants :) I tried writing unicode method , but it has no effect.I dont know why.And when I try to use maphdid_id, it says it deosnt exist On 26 Mart, 13:11, Daniel Roseman <dan...@roseman.org.uk> wrote: > On Mar 26, 4:44 pm, Asim Yuksel <a.sinanyuk...@gmail.com> wrote: > > > Yes foreignkey is an object but there must be a way to display the > > value in a list_display. I am a newbie too. self.maphdid.id doesnt > > work > > The underlying id field is called "maphdid_id", so you should be able > to use that. But I have no idea why you'd want that to appear in a > list_display, it's of no use to users of your application. > > Much more worthwhile is to define a useful __unicode__ method on the > Tblmaphds model itself, which will then appear in the list_display in > place of 'Tblmaphds object'. > -- > DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: ForeignKeyField
Yes foreignkey is an object but there must be a way to display the value in a list_display. I am a newbie too. self.maphdid.id doesnt work On 26 Mart, 06:05, Thierry Chich <thierry.ch...@gmail.com> wrote: > Le vendredi 26 mars 2010 04:14:51, Asim Yuksel a écrit : > > > I have a question about model.ForeignKey field.Foreign key fields are > > shown as object in admin page. How can I show them in other types like > > integer type > > for example I have a Model like this: > > > class Advisor(models.Model): > > > advisorid = models.IntegerField(primary_key=True, > > db_column='advisorId') > > maphdid = models.ForeignKey(Tblmaphds, db_column='maPhDId') > > def __str__(self): > > return smart_str('%s' % (self.maphdid)) > > def __unicode__(self): > > return smart_str('%s' % (self.maphdid)) > > class Meta: > > db_table = 'Advisor' > > > The problem is I see the maphdid value as "Tblmaphds object" instead > > of a normal integer value. > > > What should I do to see a integer value? > > I am not sure of what I say because I just begin with django, but it seems to > me that you are confusing foreignkey in models and foreignkey in SQL database. > For me, a foreignkey in django is an object, not an id. > > So, it seems to me that maphdid is an object Tblmaphds. If you want to print > the Tblmaphds.id value, you shoud have > to write > return smart_str('%s' % (self.maphdid.id)) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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: ForeignKeyField
I cant show the foreignkey values in a list_display. I tried raw_id_fields but didnt work On 25 Mart, 23:18, Shawn Milochikwrote: > This should help: > > http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#raw-id-fields > > Shawn -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.
ForeignKeyField
I have a question about model.ForeignKey field.Foreign key fields are shown as object in admin page. How can I show them in other types like integer type for example I have a Model like this: class Advisor(models.Model): advisorid = models.IntegerField(primary_key=True, db_column='advisorId') maphdid = models.ForeignKey(Tblmaphds, db_column='maPhDId') def __str__(self): return smart_str('%s' % (self.maphdid)) def __unicode__(self): return smart_str('%s' % (self.maphdid)) class Meta: db_table = 'Advisor' The problem is I see the maphdid value as "Tblmaphds object" instead of a normal integer value. What should I do to see a integer value? -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.