I am using the following code, so that I can have different change lists that 
depend on some variable. The way the stuff member does not have to manually 
apply the filter each time he/she enters the list:


class CourseApplicationAdminS12(CourseParticipantAdmin):
    year = 2012
    def queryset(self, request):
        req = super(CourseApplicationAdminS12, self).queryset(request)
        return req.filter(course__period__start_date__year = self.year)
    class Meta:        
        verbose_name_plural = _('Participant Summer 2012')
        verbose_name = _('Participants Summer 2012’)

class CourseApplicationAdminS13(CourseParticipantAdmin):
    year = 2013
    def queryset(self, request):
        req = super(CourseApplicationAdminS13, self).queryset(request)
        return req.filter(course__period__start_date__year = self.year)
    class Meta:        
        verbose_name_plural = _('Participant Summer 2013')
        verbose_name = _('Participants Summer 2013')

def create_modeladmin(modeladmin, model, name = None):
    class  Meta:
        proxy = True
        app_label = model._meta.app_label
    
    attrs = {'__module__': 'applications', 'Meta': Meta}

    newmodel = type(name, (model,), attrs)
    admin.site.register(newmodel, modeladmin)
    return modeladmin

create_modeladmin(CourseApplicationAdminS12, name='Participation Summer %i' % 
2012, model=CourseApplication)
create_modeladmin(CourseApplicationAdminS13, name='Participation Summer %i' % 
2013, model=CourseApplication)


as you can see, I am creating a ModelAdmin and some proxy model and all that 
differs it actually the name and the year attibute of the AdminClass, which 
gets used in queryset to filter the objects.

This seems like a lot of coding for such a simple task. It works but seems not 
to be right !?

Another idea that just comes to my mind is to have the filter in the Get 
parameter and make links available in the admin interface?

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
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.

Reply via email to