django-admin

Creating an entire web application using django admin

I was thinking that django admin is an utility to provide trusted administrators of the site, full access to the site's data model. However, after going through django admin in detail, I understand that it is very powerful set of views and templates that one can use to create an entire application. How often do you create an entire app...

Select List Filtering in Django Admin

I'm new to Django and so far I like it a lot but I've come to a bit of a roadblock and I'm not sure if it is in the admin that I can change this, or in my models. I have a relationship that looks like this: Unfortunately due to circumstances I can't link the actual code class A: class B: a = models.ForeignKey(A) class C: a = m...

Django - Overriding get_form to customize admin forms based on request

I've tried various methods to achieve this. I decided against overriding formfield_for_dbfield as it's doesn't get a copy of the request object and I was hoping to avoid the thread_locals hack. I settled on overriding get_form in my ModelAdmin class and tried the following: class PageOptions(admin.ModelAdmin): def get_form(self, r...

Django: Permalinks for Admin

I know the link template to reach an object is like following: "{{ domain }}/{{ admin_dir }}/{{ appname }}/{{ modelname }}/{{ pk }}" Is there a way built-in to get a permalink for an object? from django.contrib import admin def get_admin_permalink(instance, admin_site=admin.site): # returns admin URL for instance change page ...

Getting Django admin url for an object

Before Django 1.0 there was an easy way to get the admin url of an object, and I had written a small filter that I'd use like this: <a href="{{ object|admin_url }}" .... > ... </a> Basically I was using the url reverse function with the view name being 'django.contrib.admin.views.main.change_stage' reverse( 'django.contrib.admin.views....

Django admin - inline inlines (or, three model editing at once)

Hi, I've got a set of models that look like this: class Page(models.Model): title = models.CharField(max_length=255) class LinkSection(models.Model): page = models.ForeignKey(Page) title = models.CharField(max_length=255) class Link(models.Model): linksection = models.ForeignKey(LinkSection) text = models.CharFiel...

Custom actions in Django Admin

Hi all, in my Django app i have a Newsletter model. Now I'd like to be able to send the newsletter (and even resend it) from Django Admin. I could do this with a hook on the Model.save() method but is there another way that is not tied to the Model? Thanks ...

Django Admin: How to access the request object in admin.py, for list_display methods?

I've added a method 'highlight_link' to my model's admin.py class: class RadioGridAdmin(admin.ModelAdmin): list_display = ('start_time', highlight_link) def highlight_link(self): return ('some custom link') admin.site.register(RadioGrid, RadioGridAdmin) It returns a custom link for (I've left out highlight_link.short_...

Django Model: Returning username from currently logged in user

I'm working on a Django app for hosting media (specifically audio and images). I have image galleries and photos separate in my model, and have them linked with a ForeignKey (not sure if that's correct, but still learning). What I need is for the Album class's __unicode__ to return the album owner's username. class Album(models.Model): ...

How possible to show external links in Django Admin Interface ?

I need to generate external links in admin interface grid column, but they shows as html code: <a href="http://www.site.com/"&gt;site&lt;/a&gt; Admin interface translates my links as html-entities and they doesn't shows as right links. Is it possible to show external links there, not html code? I think list_display_links doesn't work...

Group models in django admin

Is there any way to group the models in django admin interface? I currently have an app called requests with the following models showing in the admin site: **Requests** Divisions Hardware Requests Hardware Types Requests Software Requests Software Types I would like the divisions, Software Requests and Hardware Requests to be groupe...

Manipulating Data in Django's Admin Panel on Save

Ok, so here's the skinny: # models.py class Article( models.Model ): title = models.CharField( max_length = 255 ) author = models.ForeignKey( User ) published_at = models.DateTimeField( auto_now_add = True ) body = models.TextField( ) def __unicode__( self ): return self.titl...

Default value for field in Django model

Suppose I have a model: class SomeModel(models.Model): id = models.AutoField(primary_key=True) a = models.CharField(max_length=10) b = models.CharField(max_length=7) Currently I am using the defauly admin to create/edit objects of this type. How do I remove the field b from the admin so that each object cannot be created w...

Standard Django way for letting users edit rich content

I have a Django website in which I want site administrators to be able to edit rich content. Suppose we're talking about an organizational info page, which might include some pictures, and some links, where the page is not as structured as a news page (which updates with news pieces every few days), but still needs the ability to be easi...

Django admin display groups horizontally

How do I get Django admin to display groups horizontally? If I have 3 adjacent datetime fields, I'd rather them take up 1 row, not 3. ...

Why is django slow to generate select boxes for foreign keys?

I have an admin view which contains four foreign keys each with a few thousand entries. It is slow to appear in the browser. If I change the django model to eliminate the select boxes by adding raw_id_fields things become nice and snappy. So the slowness is due to the population of the select drop downs and also this is a known issue s...

How to store data in Django Model without having an input field

I have model for example like this: class Meeting(models.Model): date = models.DateTimeField(default=datetime.datetime.now) team = models.CharField(max_length=100) class Meta: verbose_name_plural = u'Meetings' ordering = ['-date', 'team'] def __unicode__(self): return u'%s %s' % (self.date, self...

How to limit choice field options based on another choice field in django admin

I have the following models: class Category(models.Model): name = models.CharField(max_length=40) class Item(models.Model): name = models.CharField(max_length=40) category = models.ForeignKey(Category) class Demo(models.Model): name = models.CharField(max_length=40) category = models.ForeignKey(Category) item =...

ManyToManyFields in Django Admin

I'm using Photologue in my application, and I really like the ManyToManyField selector that appears in the admin app (two multi-select boxes with arrows for moving items between the selected and non-selected states, along with "Choose All" and "Clear All" options). I'm using very similar code in my own model, but my ManyToManyField sele...

Overriding the save method in Django ModelForm

I'm having trouble overriding a modelform save method. This is the error I'm receiving: Exception Type: TypeError Exception Value: save() got an unexpected keyword argument 'commit' My intentions are to have a form submit many values for 3 fields, to then create an object for each combination of those fields, and to save each of th...