WebFaction
Community site: login faq

Hello,

Question about django admin interface how can I write into models.py + admin.py and basically show up instedad of label a dropdown that has only 3 options example:

Models.py

class Page(models.Model):
    title = models.CharField(max_length=200, blank=True, verbose_name="Video Title")
    pub_date = models.DateTimeField('Order Videos by Date')
    icon = models.CharField(max_length=150, blank=True, verbose_name="Media Label Icons")
    link = models.CharField(max_length=150, blank=True, verbose_name="Link")

I would like to have 'icon" to be a dropdown that has 3 options would say like:

  1. adobe icon
  2. word icon
  3. zip file

Each icon has link like:

  • http://www.example.com/media/adobe.png
  • http://www.example.com/media/word.png
  • http://www.example.com/media/zip.png

What it does it creates this (screenshot) - the icons:

http://cl.ly/image/1v020Z0x3e40

They always will have same path (for the icons) and be always 3 so I was thinking the user dont need to specify url in the label but can choose (adobe, word, zip) and it will automatically add that url link to html.

How to correctly write it in models.py & admin.py?

Thanks for help

asked 29 Aug '12, 14:34

rentgeeen
4721319
accept rate: 0%

edited 29 Aug '12, 17:03

seanf
12.2k41836


Providing everything you need to be able to produce the end result you want is not practical, as what you need is not exact line by line code but to have a fundamental understanding of Django and HTML.

I suggest you read the official Django documentation and build the demo votes app locally.

In all reality most of the work is going to be the template and thus the HTML embedded in the Django template. To learn what HTML you should read the W3Cs documentation on the HTML specification for forms.

permanent link

answered 29 Aug '12, 19:33

johns
5.3k312
accept rate: 23%

I already built a lots of django websites and they have so many features + languages so I understand how templates all works. What I am trying to do is maybe I can show you on the screenshot

http://cl.ly/image/3m0h0s0w192Z

Media Label Icons, in that label I specify link to image (icon): there a only 3 links: adobe, word, zip like here:

http://cl.ly/image/1v020Z0x3e40

I need that Label to be DROPDOWN that you can choose 1 of 3 and it has link associated with it.

So in the template I do:

*img src="{{ page.mediaicons }}" border="0" *

It will pick the link which you put in the label, so instead of writing the entire link id admin I want to have for user-friendly dropdown to choose adobe, work or zip.

I dont know how to write it in admin....

models have:

icon = models.CharField(max_length=150, blank=True, verbose_name="Media Label Icons")

admin:

class PageAdmin(admin.ModelAdmin):

fieldsets = [ (None, {'fields': ['homepageurl', 'pageurl', 'icon', 'link', 'description',]}), ] list_display = ('homepageurl', 'pageurl',) admin.site.register(Page, L10n(Page, PageAdmin))

The result is practical would be practical, not to write entire weblink to icon lable for user that doesnt understand links or web at all, I want to user just choose.

I know something like this is possible with "django choice" but dont know the syntax to implement it in the admin or define it in the model...

If you in webfaction I can open a ticket and show you entire solution that you would understand in case you willing to help me :)

thanks a lot

(29 Aug '12, 21:34) rentgeeen

Although the admin interface is useful for rapid development, often customizing it is not as straight forward as you would expect. For this reason I suggest this chapter from the Django book which covers editing the admin interface in detail. Pay special attention to the 'The Zen of Admin' section. For the most part the admin is designed to be a raw view of the data, and not provide customization, if you want that you should build a regular view. If you look for answers to this on other forums or blogs this is the general consensus I have found. It is possible, however providing the exact code is not something we can do, it will take testing/debugging by you to see what works for your application.

(30 Aug '12, 00:29) johns
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×908
×40
×7
×2
×1

question asked: 29 Aug '12, 14:34

question was seen: 4,482 times

last updated: 30 Aug '12, 00:33

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM