Re: Stuck at filtering/slicing

2011-05-25 Thread Michel30
hmm had a send accident..

I tried
 
Documentrevision.objects.values('documentid').annotate(Max('versionnumber')).filter
and it retrieves a list of values, but I need the objects to use later
on

On May 25, 2:40 pm, Michel30  wrote:
> I've tried annotate before but I ran into the issue that it returns a
> list of values I believe?
> I tried:
>
> On May 25, 1:40 pm, Jani Tiainen  wrote:
>
> > On Wed, 2011-05-25 at 02:59 -0700, Michel30 wrote:
> > > Hello all,
>
> > > I have the following model:
>
> > > class Documentrevision(models.Model):
> > >     docrevid = models.AutoField(primary_key=True,
> > > db_column='DocRevID')
> > >     documentid = models.ForeignKey(Document, db_column='DocumentID')
> > >     submitterid = models.ForeignKey('Author', db_column='SubmitterID')
> > >     documenttitle = models.CharField(max_length=765,
> > > db_column='DocumentTitle')
> > >     publicationinfo = models.TextField(db_column='PublicationInfo',
> > > blank=True)
> > >     versionnumber = models.IntegerField(db_column='VersionNumber')
> > >     abstract = models.TextField(db_column='Abstract', blank=True)
> > >     revisiondate = models.DateTimeField(null=True,
> > > db_column='RevisionDate', blank=True)
> > >     timestamp = models.DateTimeField(db_column='TimeStamp')
> > >     obsolete = models.IntegerField(null=True, db_column='Obsolete',
> > > blank=True)
> > >     keywords = models.CharField(max_length=720, db_column='Keywords',
> > > blank=True)
> > >     note = models.TextField(db_column='Note', blank=True)
> > >     demanaged = models.IntegerField(null=True, db_column='Demanaged',
> > > blank=True)
>
> > > Now I want to retrieve all entries that match obsolete=0, then order
> > > on revisiondate and docrevid and last get only the highest
> > > versionnumber for each group of documentid.
>
> > > I got this far:
> > >     found_entries =
> > > Documentrevision.objects.filter(obsolete=0).order_by('-revisiondate','-
> > > docrevid')
>
> > > This gives me all versionnumbers though: I've been trying several ways
> > > to slice, group , do for-loops and can't get it to work..
> > > Any ideas are greatly appreciated :-)
> > > Thanks
>
> > DocumentRevision.objects.values('documentid').annotate(Max('docrevid)').filter(...)
>
> > Should do the trick.
>
> > --
>
> > Jani Tiainen
>
>

-- 
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.



Re: Stuck at filtering/slicing

2011-05-25 Thread Michel30
I've tried annotate before but I ran into the issue that it returns a
list of values I believe?
I tried:


On May 25, 1:40 pm, Jani Tiainen  wrote:
> On Wed, 2011-05-25 at 02:59 -0700, Michel30 wrote:
> > Hello all,
>
> > I have the following model:
>
> > class Documentrevision(models.Model):
> >     docrevid = models.AutoField(primary_key=True,
> > db_column='DocRevID')
> >     documentid = models.ForeignKey(Document, db_column='DocumentID')
> >     submitterid = models.ForeignKey('Author', db_column='SubmitterID')
> >     documenttitle = models.CharField(max_length=765,
> > db_column='DocumentTitle')
> >     publicationinfo = models.TextField(db_column='PublicationInfo',
> > blank=True)
> >     versionnumber = models.IntegerField(db_column='VersionNumber')
> >     abstract = models.TextField(db_column='Abstract', blank=True)
> >     revisiondate = models.DateTimeField(null=True,
> > db_column='RevisionDate', blank=True)
> >     timestamp = models.DateTimeField(db_column='TimeStamp')
> >     obsolete = models.IntegerField(null=True, db_column='Obsolete',
> > blank=True)
> >     keywords = models.CharField(max_length=720, db_column='Keywords',
> > blank=True)
> >     note = models.TextField(db_column='Note', blank=True)
> >     demanaged = models.IntegerField(null=True, db_column='Demanaged',
> > blank=True)
>
> > Now I want to retrieve all entries that match obsolete=0, then order
> > on revisiondate and docrevid and last get only the highest
> > versionnumber for each group of documentid.
>
> > I got this far:
> >     found_entries =
> > Documentrevision.objects.filter(obsolete=0).order_by('-revisiondate','-
> > docrevid')
>
> > This gives me all versionnumbers though: I've been trying several ways
> > to slice, group , do for-loops and can't get it to work..
> > Any ideas are greatly appreciated :-)
> > Thanks
>
> DocumentRevision.objects.values('documentid').annotate(Max('docrevid)').filter(...)
>
> Should do the trick.
>
> --
>
> Jani Tiainen

-- 
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.



Re: Stuck at filtering/slicing

2011-05-25 Thread Jani Tiainen
On Wed, 2011-05-25 at 02:59 -0700, Michel30 wrote:
> Hello all,
> 
> I have the following model:
> 
> class Documentrevision(models.Model):
> docrevid = models.AutoField(primary_key=True,
> db_column='DocRevID')
> documentid = models.ForeignKey(Document, db_column='DocumentID')
> submitterid = models.ForeignKey('Author', db_column='SubmitterID')
> documenttitle = models.CharField(max_length=765,
> db_column='DocumentTitle')
> publicationinfo = models.TextField(db_column='PublicationInfo',
> blank=True)
> versionnumber = models.IntegerField(db_column='VersionNumber')
> abstract = models.TextField(db_column='Abstract', blank=True)
> revisiondate = models.DateTimeField(null=True,
> db_column='RevisionDate', blank=True)
> timestamp = models.DateTimeField(db_column='TimeStamp')
> obsolete = models.IntegerField(null=True, db_column='Obsolete',
> blank=True)
> keywords = models.CharField(max_length=720, db_column='Keywords',
> blank=True)
> note = models.TextField(db_column='Note', blank=True)
> demanaged = models.IntegerField(null=True, db_column='Demanaged',
> blank=True)
> 
> Now I want to retrieve all entries that match obsolete=0, then order
> on revisiondate and docrevid and last get only the highest
> versionnumber for each group of documentid.
> 
> I got this far:
> found_entries =
> Documentrevision.objects.filter(obsolete=0).order_by('-revisiondate','-
> docrevid')
> 
> This gives me all versionnumbers though: I've been trying several ways
> to slice, group , do for-loops and can't get it to work..
> Any ideas are greatly appreciated :-)
> Thanks
> 

DocumentRevision.objects.values('documentid').annotate(Max('docrevid)').filter(...)

Should do the trick.

-- 

Jani Tiainen


-- 
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.



Stuck at filtering/slicing

2011-05-25 Thread Michel30
Hello all,

I have the following model:

class Documentrevision(models.Model):
docrevid = models.AutoField(primary_key=True,
db_column='DocRevID')
documentid = models.ForeignKey(Document, db_column='DocumentID')
submitterid = models.ForeignKey('Author', db_column='SubmitterID')
documenttitle = models.CharField(max_length=765,
db_column='DocumentTitle')
publicationinfo = models.TextField(db_column='PublicationInfo',
blank=True)
versionnumber = models.IntegerField(db_column='VersionNumber')
abstract = models.TextField(db_column='Abstract', blank=True)
revisiondate = models.DateTimeField(null=True,
db_column='RevisionDate', blank=True)
timestamp = models.DateTimeField(db_column='TimeStamp')
obsolete = models.IntegerField(null=True, db_column='Obsolete',
blank=True)
keywords = models.CharField(max_length=720, db_column='Keywords',
blank=True)
note = models.TextField(db_column='Note', blank=True)
demanaged = models.IntegerField(null=True, db_column='Demanaged',
blank=True)

Now I want to retrieve all entries that match obsolete=0, then order
on revisiondate and docrevid and last get only the highest
versionnumber for each group of documentid.

I got this far:
found_entries =
Documentrevision.objects.filter(obsolete=0).order_by('-revisiondate','-
docrevid')

This gives me all versionnumbers though: I've been trying several ways
to slice, group , do for-loops and can't get it to work..
Any ideas are greatly appreciated :-)
Thanks

-- 
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.