Tuesday, July 27, 2010

Re: save a values_list to a charfield

It is a bit of a last minute deal and will be changed after today, but
we had a handful of "improvements" handed down to us from management
and this was the fastest thing we could come up with using some old
mysql query logic and several already built templates for output.

I appreciate the help.

On Jul 27, 2:49 pm, ringemup <ringe...@gmail.com> wrote:
> ', '.join(primary_ids)
>
> The fact that you're doing this with foreign keys, though, suggests to
> me that you may have a database normalization problem.
>
> On Jul 27, 3:26 pm, Nick <nickt...@gmail.com> wrote:
>
> > I am getting this to save but I can't get it to output properly
>
> > it's outputting as [16L, 451L, 521L] for a list of id's, which it
> > should according to documentation.  However, how can I output it like
> > this 16, 451, 521
>
> > On Jul 27, 12:11 pm, Nick <nickt...@gmail.com> wrote:
>
> > > I am needing to do some duct taping for a project that is going on
> > > right now. In it I need to take a values_list of id's from a
> > > ManyToMany field and save those values to a varchar field so a mysql
> > > query can access the values. I am working with two different sets of
> > > developers and this is the best we can come up with in such a short
> > > period of time
>
> > > Here is the model:
>
> > > Candidate
> > >     filing_id = models.IntegerField()
> > >     name = models.CharField()
>
> > > Race:
> > >     name = models.CharField()
> > >     primary_advance = models.ManyToManyField('Candidate')
> > >     primary_advnace_list = models.CahrField()
>
> > >     def(save, *args, **kwargs):
> > >         primary_ids = self.primary_advace.values_list('id', flat=True)
> > >         if primary_ids.count() > 0:
> > >             primary_advance_list = primary_ids
> > >         else:
> > >             primary_advance_list = []
> > >         super(Race, self).save(*args, **kwargs)
>
> > > I've tried this but I'm coming back with empty values for the list
> > > fields.

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate