I have successfully created a little app and i would like to leverage
the already existing admin interface rather than reinvent the wheel
and create my own table listings.... I have managed to do this fine
for simple models but in this case i have a custom queryset that i
would like to use.

Essentially I have a Report that is contains multiple ReportItems. A
ReportItem is a subset/filter of the Log model. I want to display
multiple subsets/filters of the log model all joined together in a
table in the admin interface. I have managed to do this in the
views.py but it looks basic and is missing all the funky kewl sorting
and things that is present in the admin interface.

So is there a way for me to feed my queryset querySets into the admin
interface?


--------------------------------------------------
models.py file
--------------------------------------------------

class Feed(models.Model):
    name = models.CharField(max_length=200)
    feed_url = models.CharField(max_length=200)
    active = models.BooleanField()
    def __unicode__(self):
        return self.name

class Log(models.Model):
    feed = models.ForeignKey(Feed)
    creator = models.CharField(max_length=200)
    pubdate = models.DateTimeField()
    title = models.CharField(max_length=200)
    changeset = models.IntegerField()
    changeset_url = models.CharField(max_length=200)
    description = models.CharField(max_length=200)
    category = models.CharField(max_length=200)
    qa_notes = models.CharField(max_length=200)
    status = models.IntegerField()
    def __unicode__(self):
        return self.title

class Report(models.Model):
    name = models.CharField(max_length=200)
    def __unicode__(self):
        return self.name

    @models.permalink
    def get_absolute_url(self):
        return ('vtps2.logs.views.report_detail_table', (),
{'report_id':self.id})

class ReportItem(models.Model):
    report = models.ForeignKey(Report)
    feed = models.ForeignKey(Feed)
    start = models.IntegerField()
    finish = models.IntegerField()


--------------------------------------------------
Views.py file
--------------------------------------------------

class LogTable(tables.ModelTable):
    class Meta:
        model = Log

def report_detail_table(request, report_id):
    report = get_object_or_404(Report, pk=report_id)
    # retrieve set
    querySets = Log.objects.filter(feed=0)
    for ri in report.reportitem_set.all():
        querySets = querySets | (Log.objects.filter(feed=ri.feed_id,
changeset__range=(ri.start,ri.finish)))
    # load set into table
    table = LogTable(
             querySets,
             order_by=request.GET.get('sort', 'changeset'))
    return render_to_response('logs/table.html', {'table': table})



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

Reply via email to