django-admin

user populate in django

how to populate user when we add objects and save them in django_admin site. the problem occurs when i click save button.And it shows an error like, user_id may not be null... what should i do??? thanks ...

The nested structure of the model

Prompt please next time. Availability: - Sections of the catalog, in different levels - The result of either directory Can standard methods include walking on the structure? Example: Section 1 Section 1.1 Section 1.2 Section 1.2.1 Need a list is not all sections of the heap, but first in Section 1., We choose to see secti...

how to modify the django admin urls?

Hi all, So i have a page with the following url format: http://tld/admin/main/report/, and i would like to pass a get request to the end to filter the queryset: ?q=+2 is all of my report for example. In the ReportAdmin(ModelAdmin), when overriding queryset(self, request), inside that, i'd like to do request.GET.get('somevar'), but the s...

django: admin.StackedInline show full name instead of user name

my inline: class CollaboratorInLine(admin.StackedInline): model = Collaborator extra = 0 my model: class Collaborator(models.Model): report = models.ForeignKey(Report) collaborator = models.ForeignKey(User, limit_choices_to={'groups__name':u'team1'}) def reutnName(self): return self.collaborator.get_full_n...

Django admin and MongoDB, possible at all?

I'm building a simple short URL service, ala bitly, for our company use. And I would like to use mongodb to store the data, but I will need some kind of simple interface to add/edit short url to long url mappings. The mongo documents will be very simple, something like this: { shortUrlSlug: 'pbbs', fullUrl: 'http://example.com/pean...

Make Django Admin remember my parameters after posting

Hi! I have a problems thats been bugging me for a while. I want to use dates in django admin to view entries between certain dates. To do this I have customized my changelist.html for this model and put a form in there. When posted I override the queryset method like this def queryset(self, request): qs = super(ModelAdmin, self).q...

django: order and show name conflict.

Hey; i have a model using user as a forgignKey. and in the admin, i need it show as full name instread of username. then i applied class CollaboratorInLine(admin.StackedInline): model = Collaborator #list_display = ('collaborator__collaborator_first_name') extra = 0 form =CollaboratorForm #raw_id_fields=("collabora...

Django admin search: how to allow OR operator between search terms?

django-sphinx seems to be a bit of an overkill. What's the simplest way to add such functionality? Thanks ...

django: URL dispatcher -> infinite loop

urlpatterns = patterns('', #(r'admin/main/report/', main_page_redirect), (r'^admin/', include(admin.site.urls)), (r'^', main_page_redirect), ) def main_page_redirect(request): return HttpResponseRedirect('/admin/main/report/?e=+2') then when i try to go to /localhost then it becomes a infinite loop. does anyone knows...

How do you override a the save method in Django and raise proper errors that will be caught by the Admin interface?

Hey everyone! I'm a little stumped here, I can't find what I'm looking for in the Django docs... What I want, is to be able to override the Save method of an Model. I want it to check for a certain set of conditions - if these conditions are met, it will create the object just fine, but if the conditions are not met, I want to raise an...

Django Model relationship refactor help?

I'm sorta having a django / db brainfart. In words I'm trying to come up with a better way to represent Address objects in my project. I have 5 or 6 different models that have one or more associations to an Address (Billing / Shipping / etc) and I need to allow these addresses to be created/modified/deleted. My first thought was to ...

Django ModelAdmin - fieldsets ... field 'date' missing from the form

I figured out what the problem was while writing this question. I post it anyway in case it could help someone else. The error: 'FooAdmin.fieldsets[0][1]['fields']' refers to field 'date' that is missing from the form. With the following code: # models.py from django.db import models class Foo(Base): date = models.DateField(auto_...

Django Admin: Alter how data is displayed

I have a model with a json field. The contents of which may or may not be pretty-printed, I don't really mind either way as long as the data is valid. However when it is displayed in django admin I would like for the contents of the field to be pretty printed so that it is easy to read. I don't mind if this means the pretty printed versi...

#django what method is used to represent a model field in admin

I am trying to subclass CharField with a custom unicode method. Basically, I want to be able to call my custom crypto method on the value that is returned by the default model field. I tried the following, but it seems that admin is getting the values some other way. It seems to me that this would be the most pythonic way to implement...

Choices from model in Django

I have a model that picks up the choices defined in CHOICES like this: CHOICES = ( ('1', '1'), ('2', '2'), ('3', '3'), ) class select(models.Model): first = models.CharField(max_length=3, choices=CHOICES) second = models.CharField(max_length=3, choices=CHOICES) I would like to be able to add, remove or change choices ...

Issue with Django Inline form

I have attached TestInline in the FoobarAdmin, this thing works well but i want logged in user to be pre-populated for the added_by field from django.contrib import admin from django.contrib.auth.models import User class Test(models.Model): description = models.TextField() added_on = models.DateTimeField(auto_now_add=True) ...

Django inlinemodeladmin validation - but with a generic relation

I previously had models like this: class AssemblyAnnotation(models.Model): assembly = models.ForeignKey(Assembly) type = models.ForeignKey(AssemblyAnnotationType) ... def clean(self): from django.core.exceptions import ValidationError if not self.type.can_annotate_aliases and self.assembly.alias_of_id is ...

How to have previous and next button in the django admin (change_form)

I want to modify the django admin for a particular model to provide the following behaviour. A user make a search on the change_list page. The the user click a specific entry and he lands on the change_form for that entry. Nothing different to the usual. Now, what I want is a mean to navigate the former search results. Basically next a...

django extend ModelAdmin fieldsets and keep defaults

is there a nice way to add custom items to a subclassed ModelAdmin fieldset, ie have it keep all the defaults and just some extras. (i know i could add all the defaults back myself, but was hoping for a nicer way) ...

Admin site automatically get current user

I am making a blog application and want to automatically add the current user when i submit a new post through the admin site. Is there any way that i could detect the current logged-in user and add it to the post. These are the models: class Post(models.Model): user = models.ForeignKey(User) title = models.CharField('Title', ma...