Re: Many to many field does not save in the main object

2020-08-28 Thread Annick Sakoua
 I found the mistake, I removed the 'for item in instance'  in my 
addcustomer function and Elesire suggestion about iterating in the 
{{customer.gp}} object  in my template helped me a lof. Thank you soo much.

Le mardi 25 août 2020 à 14:57:48 UTC+1, Annick Sakoua a écrit :

> Hi all,
> Please Help.
> I have been on this problem for 2 weeks now :(
> I have an object: customer  that has 1 manytomany relationship with 
> another object: gp.
> I created some gp instances in the admin page. When I select one gp in the 
> select dropdown list of existing gp  in my addcustomer form and submit my 
> form, the form is saved with all the information except the gp selected. I 
> only get the this: app.GeneralPractitioner.None  
> Here are bellow my different classes. 
>
> Thank you for your help :)
>
> *model.py*
>
> class Customer(models.Model):
> first_name = models.CharField(max_length=100)
> last_name = models.CharField(max_length=100)
> gp = models.ManyToManyField(GeneralPractitioner, help_text="Select your 
> general practitioner", related_name="customer")
>
>
> class GeneralPractitioner(models.Model):
> name = models.CharField(
> max_length=40,
> help_text="Enter the gp name)"
> )
> contact= models.CharField(max_length=11)
>
> def __str__(self):
> return self.name
>
> *in view.py*
>
> @login_required
> def add_customer(request):
> if request.method == 'POST':
>
> form = AddCustomerForm(request.POST)
> if form.is_valid():
> instance = form.save(commit=False)
> for item in instance:
> item.save()
> form.save_m2m()
> instance.author = request.user
>
> messages.success(request, f'Your form has been created!')
> return redirect('addcustomer')
> else:
> form = AddCustomerForm()
> return render(request, 'app/addcustomer.html', {'form': form})
>
> *customer_details.html*
>
> {% extends "app/base.html" %}
> {% load crispy_forms_tags %}
> {% block content %}
>
> 
> Firstname: {{customer.first_name}}
> Lastname: {{customer.last_name}}
> General practitioner: {{customer.gp}}
> 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6426a74f-6096-473e-87bf-3a1c4914392en%40googlegroups.com.


Re: Many to Many relationships in template

2020-02-27 Thread Gil Obradors
Hi!

https://docs.djangoproject.com/en/3.0/ref/contrib/admin/#modeladmin-objects
or
https://docs.djangoproject.com/en/3.0/intro/tutorial07/#writing-your-first-django-app-part-7

Missatge de Robb Rodirguez Jr.  del dia dv.,
28 de febr. 2020 a les 1:14:

> Good day guys, im new to django im having in many to many relationship
> display in template
>
> How can display this into a normal list..
>
> from .
> , , , ,
> ]>
>
> to.
> webadmin
> kim
> sem
> quinito
> user1
>
> Here's my code
>
> model.py
>
> class ListOfUser(models.Model):
> users = models.ManyToManyField(User, verbose_name='List of User')
>
>
>
> views.py
>
> def listofusers(request):
> userlist = ListOfUser.objects.get(id=1)
>
> form = ListofUserForms()
>
> context = {
> 'form': form,
> 'userlist': userlist
> }
> return render(request, 'listofusers.html', context)
>
>
> template
>
> {{userlist.users.all}}
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/f3e604a7-5613-4f12-8aa6-526b19ae0fc7%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK-JoTQQr%2BQODZoqWfJLNcdFsrkvLWXmUOqES0wcxSfCSHO59A%40mail.gmail.com.


Re: Many to Many field in ModelForm - with tens of thousands of records

2018-10-29 Thread Web Architect
Hi Sanjay,

Thanks for the prompt response and the approach. 

That seems to be an efficient approach - would look into auto-complete.

Thanks.

On Monday, October 29, 2018 at 5:09:50 PM UTC+5:30, Sanjay Bhangar wrote:
>
> My recommendation would be to use a bit of Javascript to implement an 
> "autocomplete" to fetch records via AJAX as the user types (with 
> perhaps a minimum of 3 characters or so), so you only ever fetch a 
> subset of records and don't overload your template. 
>
> You can find quite a few 3rd party libraries that should be able to 
> aid in setting up this behaviour, see: 
> https://djangopackages.org/grids/g/auto-complete/ - unfortunately, I 
> can't recommend a particular one right now - but most should have 
> integrations for the django admin / django forms with Many2Many or 
> ForeignKey fields. 
>
> Hope that helps, 
> Sanjay 
> On Mon, Oct 29, 2018 at 5:01 PM Web Architect  > wrote: 
> > 
> > Would also add that the server CPU usage was hitting 100% due to the 
> template loading issue. 
> > 
> > On Monday, October 29, 2018 at 4:48:54 PM UTC+5:30, Web Architect wrote: 
> >> 
> >> Hi, 
> >> 
> >> We are using django 1.11 for our ecommerce site. 
> >> 
> >> We are facing an issue with modelform and many to many field in it as 
> follows: 
> >> 
> >> Lets say there are two models: 
> >> 
> >> class A(models.Model): 
> >>c = models.CharField() 
> >> 
> >> class B(models.Model): 
> >>   a = models.ManyToManyField('A') 
> >> 
> >> Now if I define a modelform: 
> >> 
> >> class MF(models.ModelForm): 
> >>   class Meta: 
> >>   model = B 
> >>   fields = [a,] 
> >> 
> >> We are using django widget tweaks to render the fields in MF. Now if 
> there are tens of thousands of records in A, the MF form rendering causes 
> the page to hang as the widget will try to show the whole set of tens of 
> thousands of records option for field a. 
> >> 
> >> Hence, would appreciate if anyone could suggest a smart solution 
> wherein the above issue is taken care of. 
> >> 
> >> Thanks. 
> >> 
> >> 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups "Django users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to django-users...@googlegroups.com . 
> > To post to this group, send email to django...@googlegroups.com 
> . 
> > Visit this group at https://groups.google.com/group/django-users. 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/36ebab2d-7440-40bc-b5e9-a4a2897dcd3a%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e7590f4d-2658-4c8a-bfba-02a5d64cbb12%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many to Many field in ModelForm - with tens of thousands of records

2018-10-29 Thread Sanjay Bhangar
My recommendation would be to use a bit of Javascript to implement an
"autocomplete" to fetch records via AJAX as the user types (with
perhaps a minimum of 3 characters or so), so you only ever fetch a
subset of records and don't overload your template.

You can find quite a few 3rd party libraries that should be able to
aid in setting up this behaviour, see:
https://djangopackages.org/grids/g/auto-complete/ - unfortunately, I
can't recommend a particular one right now - but most should have
integrations for the django admin / django forms with Many2Many or
ForeignKey fields.

Hope that helps,
Sanjay
On Mon, Oct 29, 2018 at 5:01 PM Web Architect  wrote:
>
> Would also add that the server CPU usage was hitting 100% due to the template 
> loading issue.
>
> On Monday, October 29, 2018 at 4:48:54 PM UTC+5:30, Web Architect wrote:
>>
>> Hi,
>>
>> We are using django 1.11 for our ecommerce site.
>>
>> We are facing an issue with modelform and many to many field in it as 
>> follows:
>>
>> Lets say there are two models:
>>
>> class A(models.Model):
>>c = models.CharField()
>>
>> class B(models.Model):
>>   a = models.ManyToManyField('A')
>>
>> Now if I define a modelform:
>>
>> class MF(models.ModelForm):
>>   class Meta:
>>   model = B
>>   fields = [a,]
>>
>> We are using django widget tweaks to render the fields in MF. Now if there 
>> are tens of thousands of records in A, the MF form rendering causes the page 
>> to hang as the widget will try to show the whole set of tens of thousands of 
>> records option for field a.
>>
>> Hence, would appreciate if anyone could suggest a smart solution wherein the 
>> above issue is taken care of.
>>
>> Thanks.
>>
>>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/36ebab2d-7440-40bc-b5e9-a4a2897dcd3a%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAG3W7ZHLEPgUKqZWfLh2yqJc6wkoAMbeY_iw5zDk%2BOJHqJejOw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many to Many field in ModelForm - with tens of thousands of records

2018-10-29 Thread Web Architect
Would also add that the server CPU usage was hitting 100% due to the 
template loading issue. 

On Monday, October 29, 2018 at 4:48:54 PM UTC+5:30, Web Architect wrote:
>
> Hi,
>
> We are using django 1.11 for our ecommerce site. 
>
> We are facing an issue with modelform and many to many field in it as 
> follows:
>
> Lets say there are two models:
>
> class A(models.Model):
>c = models.CharField()
>
> class B(models.Model):
>   a = models.ManyToManyField('A')
>
> Now if I define a modelform:
>
> class MF(models.ModelForm):
>   class Meta:
>   model = B
>   fields = [a,]
>
> We are using django widget tweaks to render the fields in MF. Now if there 
> are tens of thousands of records in A, the MF form rendering causes the 
> page to hang as the widget will try to show the whole set of tens of 
> thousands of records option for field a. 
>
> Hence, would appreciate if anyone could suggest a smart solution wherein 
> the above issue is taken care of. 
>
> Thanks.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/36ebab2d-7440-40bc-b5e9-a4a2897dcd3a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many to Many fields and through table

2018-07-04 Thread johnasmith . dev
Hi Mark,

Thank you for your question, I might actually do the same. I just had 
issues on a model with 2 M2M relationships (one using an intermediary 
table, one without). 

I would just caveat what James Schneider said, there are some differences. 
My simply M2M relationship threw me Field Required Errors while the one 
using a intermediary table didn't, implicitly making the field 
required=False.

It seems like the default M2M is required as expected[1], but it's tricky 
to have the M2M through relationship not throw the same error.  

Best,
John

[1] https://code.djangoproject.com/ticket/7073
Note: I noticed this through DRF, haven't tested on a small reproducible 
case in pure Django.

On Tuesday, December 19, 2017 at 4:54:08 PM UTC-5, mark wrote:
>
> Is there any downside to creating a through table in a many to many 
> relationship when there isn't any "extra" related data, but there might be 
> in the future? 
>
> I have read that migrating from a simple m2m relationship to a m2m with a 
> through table takes some jumping through hurdles, so I am considering 
> creating the through table now in case "the powers that be" (ie end users!) 
> decide we need some extra data for the relationship in the future.
>
> Thanks!
>
> Mark
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ed333230-f9b7-4f3c-8485-1edf049f50f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many to Many fields and through table

2017-12-19 Thread Simon Charette
Hello Mark,

The only downside I can think of is that you won't be able to create
relationships from the m2m managers, you'll have to create the
relationship directly instead.

This isn't such a big issue if you plan on adding fields later to
the intermediary model later on anyway.

You can read more about the subject in the documentation[0]

Best,
Simon

[0] 
https://docs.djangoproject.com/en/2.0/topics/db/models/#intermediary-manytomany

Le mardi 19 décembre 2017 16:54:08 UTC-5, mark a écrit :
>
> Is there any downside to creating a through table in a many to many 
> relationship when there isn't any "extra" related data, but there might be 
> in the future? 
>
> I have read that migrating from a simple m2m relationship to a m2m with a 
> through table takes some jumping through hurdles, so I am considering 
> creating the through table now in case "the powers that be" (ie end users!) 
> decide we need some extra data for the relationship in the future.
>
> Thanks!
>
> Mark
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/78e4d6f9-ebe8-428a-8715-0040febf8a7e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many to Many fields and through table

2017-12-19 Thread James Schneider
On Dec 19, 2017 1:53 PM, "Mark Phillips"  wrote:

Is there any downside to creating a through table in a many to many
relationship when there isn't any "extra" related data, but there might be
in the future?

I have read that migrating from a simple m2m relationship to a m2m with a
through table takes some jumping through hurdles, so I am considering
creating the through table now in case "the powers that be" (ie end users!)
decide we need some extra data for the relationship in the future.

Thanks!


I don't believe there is any downside other than the extra few lines
required for the intermediary model definition. Functionally it is the same
AFAIK.

-James

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciV39kaHL%2BMwqdR_sba%3DrzehBw-5C5V8LqCoESiMkTBbHQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many to Many in Django Admin

2017-02-23 Thread Melvyn Sopacua
On Thursday 23 February 2017 05:22:25 José Vicente Jonas França 
wrote:

> I Like to know if its possible to display the many-to-many field in
> both pages of Model at Django Admin.
> If it is possible how can i do this?

All available in the documentation[1].
-- 
Melvyn Sopacua


[1] 
https://docs.djangoproject.com/en/1.10/ref/contrib/admin/#inlinemod
eladmin-objects

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1704408.K91Xstoank%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: Many-To-Many Relationship changes not accessible in Model.save() ?

2015-01-14 Thread Collin Anderson
Hi,

The admin first calls obj.save(), then it saves the related data.

You could try putting your logic in ModeAdmin.save_related()
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_related

Collin

On Monday, January 12, 2015 at 5:00:54 PM UTC-5, Tobias Dacoir wrote:
>
> Thanks for the links. It might be related to that bug. In my scripts I 
> added another save() and then it works of course and as for the Admin 
> Panel, until I have a solution I put a message into the help text that 
> users have to click 'save and continue' first and then 'save' afterwards. 
> Then it's fine as well. Phew at least the workaround was quickly 
> implemented, still I spend at least 1 hour on figuring out what's going 
> wrong. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1a648722-0981-4f38-a2dc-3529225dba85%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many-To-Many Relationship changes not accessible in Model.save() ?

2015-01-12 Thread Tobias Dacoir
Thanks for the links. It might be related to that bug. In my scripts I 
added another save() and then it works of course and as for the Admin 
Panel, until I have a solution I put a message into the help text that 
users have to click 'save and continue' first and then 'save' afterwards. 
Then it's fine as well. Phew at least the workaround was quickly 
implemented, still I spend at least 1 hour on figuring out what's going 
wrong. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ef541b28-43c1-4a4a-a85d-466e76e3e381%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many-To-Many Relationship changes not accessible in Model.save() ?

2015-01-12 Thread Lachlan Musicman
Is that related to this bug?

https://code.djangoproject.com/ticket/8892
https://code.djangoproject.com/ticket/10811

In short - if FK fields aren't saved as objects themselves first, then
they aren't correctly added to the new objects?

I had trouble with this once. Maybe put in a save after the get_or_creates?

cheers
L.
--
"This is a profound psychological violence here. How can one even
begin to speak of dignity in labor when one secretly feels one's job
should not exist?"

On the Phenomenon of Bullshit Jobs, David Graeber
http://strikemag.org/bullshit-jobs/


On 13 January 2015 at 08:06, Tobias Dacoir  wrote:
> I'm trying to access the value of a many-to-many relationship during the
> save() method of my model but it always returns the state it had before,
> even though the first thing I do is call super.save().
>
> class Database(models.Model):
> ...
> questions = models.ManyToManyField(Question)
> pathToAudioFiles = models.CharField(max_length=255, unique=True,
> help_text="Please type in path to folder with Audio Files, e.g.
> media/database1/*.mp3", verbose_name="Path to Audio Files")
>
> def audioData(self):
> return AudioData.objects.filter(database=self.pk)
>
> def __unicode__(self):
> return self.name
>
> def save(self, *args, **kwargs):
> super(Database, self).save(*args, **kwargs)
>
> filelist = glob.glob(self.pathToAudioFiles)
> for file in filelist:
> print "adding file %s" % file
> audioData = AudioData.objects.get_or_create(path=file,
> filename=file, database=self)
>
> # then update pairs
> for a in self.audioData():
> print 'working on %s' % a
> print self.questions.all()
> for q in self.questions.all():
> print "creating pairs with %s" % q
> pair = AudioQuestionPair.objects.get_or_create(audioData=a,
> question=q, database=self)
> for choice in q.choices:
> print "adding answer %s" % choice
> answer = Answers.objects.get_or_create(body=choice,
> audioQuestionPair=pair)
>
> In this case, the idea is that the Admin can add a new 'database' (they
> wanted to call it that way), that contains some audio files that are stored
> somewhere on disk. so far so good. Later on, using the Django Admin Panel
> the admin modifies the questions. When I use the shell I get this output,
> which is normal:
 from play.models import *
 db = Database.objects.create(name="database1",
 pathToAudioFiles="media/database1/*.mp3")
> adding file media/database1\devel_001.mp3
> adding file media/database1\devel_010.mp3
> working on media/database1\devel_001.mp3
> []
> working on media/database1\devel_010.mp3
> []
>
> Then I go to the Admin Panel and edit the associated questions of that
> object, and when I hit save:
> [12/Jan/2015 21:57:50] "GET /admin/play/database/1/ HTTP/1.1" 200 7021
> [12/Jan/2015 21:57:50] "GET /admin/jsi18n/ HTTP/1.1" 200 2372
> adding file media/database1\devel_001.mp3
> adding file media/database1\devel_010.mp3
> working on media/database1\devel_001.mp3
> []
> working on media/database1\devel_010.mp3
> []
> [12/Jan/2015 21:57:56] "POST /admin/play/database/1/ HTTP/1.1" 302 0
>
> So even though I did change the associations it's not accessible during the
> save method. It still turns up empty. How can I solve this? After hitting
> save I need to be able to process self.questions.all() right away.
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/16f1653a-764c-4163-9c13-c661513d9321%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGBeqiM_8F4jC24p0Y5uDq0%3DveCpiteAP-%3D6mb8%2BANiKCiRUmQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many-to-many Relationship Between Django Apps Fails

2014-10-21 Thread Paul Childs
Thanks man. This was a huge relief!

On Tue, Oct 21, 2014 at 2:35 PM, Collin Anderson 
wrote:

> Hi Paul,
>
> 1. How did you know!?!
>>
> I hack... kidding :). I suspected something wasn't getting loaded, and the
> list of installed apps was in the traceback you posted.
>
> 2.I have the same code in production and it was working with no problems.
>> Any idea why?
>>
> In development, most, if not all of your code is loaded and run on
> startup, and in production (at least before 1.7), things are really only
> loaded as needed. Basically with the app loading refactor and
> django.setup(), we're finally fixing problems like this.
>
> Collin
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/4_Cdw5xpx-w/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d1617a57-9a60-4727-a610-308e44789db1%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGOvLBpNtvkFbp9zOfYkpQDONfWQBmdRam6DZTrj-GOP9rrEpQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many-to-many Relationship Between Django Apps Fails

2014-10-21 Thread Collin Anderson
Hi Paul,

1. How did you know!?!
>
I hack... kidding :). I suspected something wasn't getting loaded, and the 
list of installed apps was in the traceback you posted.

2.I have the same code in production and it was working with no problems. 
> Any idea why?
>
In development, most, if not all of your code is loaded and run on startup, 
and in production (at least before 1.7), things are really only loaded as 
needed. Basically with the app loading refactor and django.setup(), we're 
finally fixing problems like this.

Collin

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d1617a57-9a60-4727-a610-308e44789db1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many-to-many Relationship Between Django Apps Fails

2014-10-21 Thread Paul Childs
I am SHOCKED. That was the problem. THANK YOU

I guess that leads to a couple of questions:

1. How did you know!?!
2.I have the same code in production and it was working with no problems. 
Any idea why?

Cheers!

On Tuesday, October 21, 2014 1:12:33 PM UTC-3, Collin Anderson wrote:
>
> Hi Paul,
>
> Try putting 'trending' in INSTALLED_APPS.
>
> Collin
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9bb45159-61ba-4b65-8bcd-37c5593efaa3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many-to-many Relationship Between Django Apps Fails

2014-10-21 Thread Collin Anderson
Hi Paul,

Try putting 'trending' in INSTALLED_APPS.

Collin

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1bcd173a-9f9f-4897-8e09-82106d1229bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many-to-many Relationship Between Django Apps Fails

2014-10-21 Thread Collin Anderson
Hi Paul,

This is great. The traceback helps. Could post more of your 
convert_queryset_to_lists. It looks like a list comprehension and there may 
be more complicated things going on there.

Thanks,
Collin

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8dfb7229-b3aa-4cbc-9703-a7db1f92815e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many-to-many Relationship Between Django Apps Fails

2014-10-21 Thread Paul Childs
Here is the stack trace...

Environment:

Request Method: POSTRequest URL: http://127.0.0.1:8000/trending/trend/
Django Version: 1.6Python Version: 2.6.7Installed 
Applications:('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'sitar')Installed Middleware:('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')

Traceback:File 
"C:\virtual_env\sitar_env2\lib\site-packages\django\core\handlers\base.py" in 
get_response
  114. response = wrapped_callback(request, *callback_args, 
**callback_kwargs)File 
"C:\virtual_env\sitar_env2\lib\site-packages\django\contrib\auth\decorators.py" 
in _wrapped_view
  22. return view_func(request, *args, **kwargs)File 
"C:\virtual_env\sitar_env2\cissimp\trending\views.py" in trend
  418. list_result = utils.convert_queryset_to_lists(q_results, 
form)File "C:\virtual_env\sitar_env2\cissimp\trending\utils.py" in 
convert_queryset_to_lists
  918.for dt in affpart.damage_types.all()]),File 
"C:\virtual_env\sitar_env2\lib\site-packages\django\db\models\manager.py" in all
  133. return self.get_queryset()File 
"C:\virtual_env\sitar_env2\lib\site-packages\django\db\models\fields\related.py"
 in get_queryset
  539. return super(ManyRelatedManager, 
self).get_queryset().using(db)._next_is_sticky().filter(**self.core_filters)File
 "C:\virtual_env\sitar_env2\lib\site-packages\django\db\models\query.py" in 
filter
  590. return self._filter_or_exclude(False, *args, **kwargs)File 
"C:\virtual_env\sitar_env2\lib\site-packages\django\db\models\query.py" in 
_filter_or_exclude
  608. clone.query.add_q(Q(*args, **kwargs))File 
"C:\virtual_env\sitar_env2\lib\site-packages\django\db\models\sql\query.py" in 
add_q
  1198. clause = self._add_q(where_part, used_aliases)File 
"C:\virtual_env\sitar_env2\lib\site-packages\django\db\models\sql\query.py" in 
_add_q
  1232. current_negated=current_negated)File 
"C:\virtual_env\sitar_env2\lib\site-packages\django\db\models\sql\query.py" in 
build_filter
  1100. allow_explicit_fk=True)File 
"C:\virtual_env\sitar_env2\lib\site-packages\django\db\models\sql\query.py" in 
setup_joins
  1351. names, opts, allow_many, allow_explicit_fk)File 
"C:\virtual_env\sitar_env2\lib\site-packages\django\db\models\sql\query.py" in 
names_to_path
  1274.  "Choices are: %s" % (name, ", 
".join(available)))
Exception Type: FieldError at /trending/trend/Exception Value: Cannot resolve 
keyword u'affectedpart' into field. Choices are: cgs_damage_code, description, 
id, reg_exp, sti


On Tuesday, October 21, 2014 1:00:36 PM UTC-3, Paul Childs wrote:
>
> Hey Collin,
>
> I had no problem in the shell...
>
>
> In [4]: AffectedPart.objects.all().count()
> Out[4]: 4090
> # pick a random AffectedPart
> In [5]: affpart = AffectedPart.objects.all()[22]
>
> In [6]: affpart.damage_types.all()
> Out[6]: []
>
> I'm not sure why this doesn't work running under the server.
>
> My models look like this:
>
> from sitar.models import (Part, DamageType, Aircraft)
> # this model is in trending.modelsclass AffectedPart(models.Model):
> res = models.ForeignKey(Res, null=True)
> arising = models.ForeignKey(Arising, null=True)
>
> aircraft = models.ForeignKey(Aircraft)
> # filled out automatically only if part to Damage/Repair type matching 
> done
> maintenance_phase = models.CharField(max_length=10,
>  choices=MAINTENANCE_PHASE_CHOICES)
> occurrence_date = models.DateField()
> partnumber = models.ForeignKey(Part)
> damage_types = models.ManyToManyField(DamageType, null=True, blank=True)
> repair_types = models.ManyToManyField(RepairType, null=True, blank=True)
>
> def __unicode__(self, ):
> if self.res:
> parent = self.res.number
>
> else:
> parent = str(self.arising)
>
> return '{0} - {1}'.format(self.partnumber.number, parent)
> # The following models are in sitar.modelsclass Part(models.Model):
> ''' This model is used to create pick-lists so the user can associate
> one or more applicable parts from a pre-defined list to
> a tracked item.
>
> It will also allow for regular CRUD functionality which is
> implemented by taking advantage of the Django admin interface. '''
>
> # Added to associate a zone with a part
> zones = models.ManyToManyField("Zone", null=True, blank=True)
>
> number = models.CharField(max_length=50, unique=True)
> description = 

Re: Many-to-many Relationship Between Django Apps Fails

2014-10-21 Thread Paul Childs
Hey Collin,

I had no problem in the shell...


In [4]: AffectedPart.objects.all().count()
Out[4]: 4090
# pick a random AffectedPart
In [5]: affpart = AffectedPart.objects.all()[22]

In [6]: affpart.damage_types.all()
Out[6]: []

I'm not sure why this doesn't work running under the server.

My models look like this:

from sitar.models import (Part, DamageType, Aircraft)
# this model is in trending.modelsclass AffectedPart(models.Model):
res = models.ForeignKey(Res, null=True)
arising = models.ForeignKey(Arising, null=True)

aircraft = models.ForeignKey(Aircraft)
# filled out automatically only if part to Damage/Repair type matching done
maintenance_phase = models.CharField(max_length=10,
 choices=MAINTENANCE_PHASE_CHOICES)
occurrence_date = models.DateField()
partnumber = models.ForeignKey(Part)
damage_types = models.ManyToManyField(DamageType, null=True, blank=True)
repair_types = models.ManyToManyField(RepairType, null=True, blank=True)

def __unicode__(self, ):
if self.res:
parent = self.res.number

else:
parent = str(self.arising)

return '{0} - {1}'.format(self.partnumber.number, parent)
# The following models are in sitar.modelsclass Part(models.Model):
''' This model is used to create pick-lists so the user can associate
one or more applicable parts from a pre-defined list to
a tracked item.

It will also allow for regular CRUD functionality which is
implemented by taking advantage of the Django admin interface. '''

# Added to associate a zone with a part
zones = models.ManyToManyField("Zone", null=True, blank=True)

number = models.CharField(max_length=50, unique=True)
description = models.CharField(max_length=100, blank=True)
comments = models.TextField(blank=True)
material = models.CharField(max_length=100, blank=True)

class Meta:
''' Order by part number field (ascending) when presenting data '''
ordering = ['number']


def __unicode__(self):
''' Return unicode description of a part instance '''
if self.description:
return '%s -- %s' % (self.number, self.description)
else:
return self.number


def get_encoded_part_number(self):
'''
   This method will remove any '/' in part numbers and replace them
   with '~' so that they can be used in URLs.
'''
return self.number.replace('/','~')

class DamageType(models.Model):

description = models.CharField(max_length=50, unique=True)
# a regular expression to account for possible spelling mistakes when
# querying the database
reg_exp = models.CharField(max_length=50, blank=True)

# Added to provide damage code for TRENDING
cgs_damage_code = models.CharField(max_length=10, blank=True,
   verbose_name="CGS Damage Code")

def __unicode__(self):
''' Return unicode representation of a DamageType instance. '''
return self.description

class Meta:
''' Order by description field (ascending) when presenting data '''
ordering = ['description']

def save(self):
''' Override the save method of the DamageType model in order to assign
a regexp if one does not exist.'''

# if the tracked item does not have a reg_exp just use
# the description
if not self.reg_exp:
self.reg_exp = self.description

super(DamageType,self).save()



/Paul

On Tuesday, October 21, 2014 12:52:45 PM UTC-3, Collin Anderson wrote:
>
> Hi Paul,
>
> Interesting. Your code should work fine. So if you run this code in the 
> shell it gives a FieldError?
>
> affpart.damage_types.all()
>
> What do your sitar models look like? There should not be a ManyToManyField 
> in the other direction.
>
> Collin
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0a43b7fb-4937-4a41-b519-0134cd64a01f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many-to-many Relationship Between Django Apps Fails

2014-10-21 Thread Daniel Roseman
On Tuesday, 21 October 2014 14:32:04 UTC+1, Paul Childs wrote:
>
> *What's been done so far:*
>
>- I was on Django 1.5 and upgraded to 1.6 (cannot go higher as we are 
>on Python 2.6) and this did not solve the problem.
>- I have researched this issue to death and cannot seem to find a 
>definite answer. Looking through the Django Project Bug Tracker, I have 
>seen similar issues but none seem to fit my particular case
>- I have resolved the problem in the past using a raw SQL call to 
>replace for example affpart.damage_types.all() with a custom function 
>but this is starting to happen more frequently now and is becoming a real 
>pain.
>
> *Description:*
>
> I have two Django apps under one project. One of the apps makes use of 
> models in another app using a many-to-many relationship.
>
> This has been working smoothly for months, and in fact it works fine on my 
> production machine but fails on my development machine. The scenario lately 
> has been that I am asked to add a new feature and when I start to work on 
> it I get a FieldError in related code which I haven't even touched.
>
> The offending line of code for this latest issue is: for dt in 
> affpart.damage_types.all()
>
> The error is:
>
> Cannot resolve keyword u'affectedpart' into field. Choices are: 
> cgs_damage_code, description, id, reg_exp, sti
>
> The error occurs in the bowels of Django in the query.py module.
>
> From a high-level, this error occurs when I am trying to use a 
> Many-to-many between models in different Django apps. For example, an 
> affected part can have more than one type of damage and a damage type can 
> be found on different affected parts.
>
> The two apps are: trending and sitar
>
> sitar was built first and has the models that I want to use from trending.
>
> In trending, my models.py file has an AffectedPart model something like 
> this:
>
> from sitar.models import (Part, DamageType, Aircraft)
> class AffectedPart(models.Model):
> ...
>
> occurrence_date = models.DateField()
> partnumber = models.ForeignKey(Part)
> damage_types = models.ManyToManyField(DamageType, null=True, blank=True)
> repair_types = models.ManyToManyField(RepairType, null=True, blank=True)
>
> .If anyone has a solution to this or knows of best practices for models in 
> one application having many-to-many relationships with models in another 
> application I would love to hear it.
>
> Thanks
>

There aren't any problems that I'm aware of with many-to-many fields in any 
recent version of Django, and the fact that some of them are in other apps 
should not make the slightest difference.

However in order for us to help you you're going to need to provide more 
information: in particular, you should show the exact template code you're 
using, the other model, and most importantly the full traceback for the 
error.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ec946d64-8093-45ec-a47e-29b55cf4bf6d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many-to-many Relationship Between Django Apps Fails

2014-10-21 Thread Collin Anderson
Hi Paul,

Interesting. Your code should work fine. So if you run this code in the 
shell it gives a FieldError?

affpart.damage_types.all()

What do your sitar models look like? There should not be a ManyToManyField 
in the other direction.

Collin

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6ed2b381-07d8-45f0-ace4-becbff6ae2c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: many-to-many between apps

2013-07-31 Thread Mike Dewhirst

On 31/07/2013 5:08pm, Mike Dewhirst wrote:

Is it possible to establish a many-to-many relationship between a model
in one app and a model in another app?


Yes. I needed to avoid importing the class and use ...

class Region(models.Model):
  ... various fields ...
  ref = models.ManyToManyField('item.Reference')

Lovely!

Thanks for Django



I've just tried to do it and run into what I think is circular import
trouble. This is a retro-fit after initial deployment.

#in item.models.reference
class Reference(models.Model):
 ... various fields ...
 class Meta:
 app_label = 'item'

#in item.models.reference_region
from company import Region

class Reference_Region(models.Model):
 region = models.ForeignKey(Region)
 reference = models.ForeignKey(Reference)
 class Meta:
 app_label = 'item'


#in company.models.region
from item import Reference

class Region(models.Model):
 ... various fields ...
 ref = models.ManyToManyField(Reference)

I have tried it the other way declaring the many-to-many field in
Reference and the same thing happens.

ImportError: cannot import name Reference
and
ImportError: cannot import name Region
respectively

Any ideas appreciated

Thanks

Mike



--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: many-to-many queryset question

2012-01-07 Thread Carsten Fuchs

Hi Peter,

Am 2012-01-07 03:40, schrieb Peter of the Norse:

One possibility is to try two excludes.

bad_authors = Authors.objects.exclude(pk__in=SetOfAuthors)
qs = Entry.objects.exclude(authors__in=bad_authors)

This will return all entries that don't have authors in SetOfAuthors. It might 
even be
easier, if you can skip creating SetOfAuthors in the first place.



That works very well!  :-)
Thank you very much for your help!

Best regards,
Carsten



--
   Cafu - the open-source Game and Graphics Engine
for multiplayer, cross-platform, real-time 3D Action
  Learn more at http://www.cafu.de

--
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: many-to-many queryset question

2012-01-06 Thread Peter of the Norse
One possibility is to try two excludes.

bad_authors = Authors.objects.exclude(pk__in=SetOfAuthors)
qs = Entry.objects.exclude(authors__in=bad_authors)

This will return all entries that don't have authors in SetOfAuthors. It might 
even be easier, if you can skip creating SetOfAuthors in the first place.

On Dec 6, 2011, at 12:19 PM, Felipe Morales wrote:

> could you possibly show the query generated?... 
> 
> # print qs.query
> 
> 2011/12/6 Carsten Fuchs 
> Hi all,
> 
> looking at the example models Author and Entry at 
> https://docs.djangoproject.com/en/1.3/topics/db/queries/, I would like to run 
> a query like this:
> 
>SetOfAuthors = Authors.objects.filter(...)
>qs = Entry.objects.filter(authors__in=SetOfAuthors)
> 
> such that (pseudo-code):
> 
>for e in qs:
>"e.authors is a subset of (or equal to) SetOfAuthors"
> 
> However, when I try it, the true result seems to be an intersection:
> 
>for e in qs:
>"There is (at least one) an author in e.authors that is also 
> in SetOfAuthors"
> 
> 
> How do I have to phrase the query in order to obtain only entries whose 
> authors are all in SetOfAuthors?
> 
> Best regards,
> Carsten
> 
> 
> 
> -- 
>   Cafu - the open-source Game and Graphics Engine
> for multiplayer, cross-platform, real-time 3D Action
>  Learn more at http://www.cafu.de
> 
> -- 
> 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.
> 
> 
> 
> 
> -- 
> Felipe Morales C.
> Ingenierío de Ejecución en Computación e Informática.
> 
> 
> -- 
> 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.

Peter of the Norse
rahmc...@radio1190.org



-- 
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: many-to-many queryset question

2011-12-06 Thread Felipe Morales
could you possibly show the query generated?...

# print qs.query

2011/12/6 Carsten Fuchs 

> Hi all,
>
> looking at the example models Author and Entry at
> https://docs.djangoproject.**com/en/1.3/topics/db/queries/,
> I would like to run a query like this:
>
>SetOfAuthors = Authors.objects.filter(...)
>qs = Entry.objects.filter(authors__**in=SetOfAuthors)
>
> such that (pseudo-code):
>
>for e in qs:
>"e.authors is a subset of (or equal to) SetOfAuthors"
>
> However, when I try it, the true result seems to be an intersection:
>
>for e in qs:
>"There is (at least one) an author in e.authors that is
> also in SetOfAuthors"
>
>
> How do I have to phrase the query in order to obtain only entries whose
> authors are all in SetOfAuthors?
>
> Best regards,
> Carsten
>
>
>
> --
>   Cafu - the open-source Game and Graphics Engine
> for multiplayer, cross-platform, real-time 3D Action
>  Learn more at http://www.cafu.de
>
> --
> 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
> .
>
>


-- 
Felipe Morales C.
Ingenierío de Ejecución en Computación e Informática.

-- 
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: Many to many fields to string

2010-08-12 Thread Steve Holden
On 8/12/2010 8:11 PM, Wendy wrote:
> Thanks so much both of you, totally works and makes sense.  I used
> Joseph's version because of the commas, but they both helped me
> understand what was happening.
> I notice that it seems to be ok to put the if statement on one line:
> 
> {% if filmmakers|length > 2 and not forloop.first %}, {% endif %}
> 
> is that generally ok, or do I want to indent everything and balance
> the if/endif statements?

That's as much a matter of personal taste as anything else. Some people
like their HTML to look pretty, but the browsers don't care. You can
omit the irrelevant whitespace in your output using the {% spaceless %}
tag - see

  http://docs.djangoproject.com/en/dev/ref/templates/builtins/#spaceless

So my own personal taste is to lay everything out for maximum ease of
understanding.

regards
 Steve
-- 
DjangoCon US 2010 September 7-9 http://djangocon.us/

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

2010-08-12 Thread Wendy
Thanks so much both of you, totally works and makes sense.  I used
Joseph's version because of the commas, but they both helped me
understand what was happening.
I notice that it seems to be ok to put the if statement on one line:

{% if filmmakers|length > 2 and not forloop.first %}, {% endif %}

is that generally ok, or do I want to indent everything and balance
the if/endif statements?

Thanks again,
Wendy

On Aug 11, 3:18 pm, Joseph Spiros  wrote:
> You'll want to loop through the objects and print the appropriate
> property of the objects that consists of just the name. Here's some
> template code that does that, and also separates with commas and "and",
> using a serial comma (aka Oxford comma).
>
> (This assumes that your Filmmaker model has a "name" property/field)
>
> {% with film.filmmakers.all as filmmakers %}{% for filmmaker in
> filmmakers %}{% if filmmakers|length > 2 and not forloop.first %}, {%
> endif %}{% if forloop.last and not forloop.first %} and {% endif %}{{
> filmmaker.name }}{% endfor %}
>
> Hope that helps!
>
> On 8/11/10 3:53 PM, Wendy wrote:
>
>
>
> > Hello,
> > I'm just getting started, and I'm returning a many to many object in
> > my template:
>
> > p>{{ film.filmmakers.all }}
>
> > So it's displaying the list:
>
> > [, ]
>
> > Can anyone tell me how to return just a string of the names?
> > I'm still getting acclimated to python syntax.
>
> > Actually in a perfect world, it would be great to concatenate the
> > names, and add an 'and' b4 the last one, I imagine this is done
> > frequently?
>
> > Thanks,
> > Wendy
>
> --
> Joseph Spiros
> iThink Software
> joseph.spi...@ithinksw.com
> +1 (440) 707-6855

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

2010-08-11 Thread Joseph Spiros
Er, I forgot to add an {% endwith %} at the end. You don't HAVE to use
the with tag at all, but it can make things a bit easier.

On 8/11/10 6:18 PM, Joseph Spiros wrote:
> You'll want to loop through the objects and print the appropriate
> property of the objects that consists of just the name. Here's some
> template code that does that, and also separates with commas and "and",
> using a serial comma (aka Oxford comma).
> 
> (This assumes that your Filmmaker model has a "name" property/field)
> 
> {% with film.filmmakers.all as filmmakers %}{% for filmmaker in
> filmmakers %}{% if filmmakers|length > 2 and not forloop.first %}, {%
> endif %}{% if forloop.last and not forloop.first %} and {% endif %}{{
> filmmaker.name }}{% endfor %}
> 
> Hope that helps!
> 
> On 8/11/10 3:53 PM, Wendy wrote:
>> Hello,
>> I'm just getting started, and I'm returning a many to many object in
>> my template:
>>
>> p>{{ film.filmmakers.all }}
>>
>> So it's displaying the list:
>>
>> [, ]
>>
>> Can anyone tell me how to return just a string of the names?
>> I'm still getting acclimated to python syntax.
>>
>> Actually in a perfect world, it would be great to concatenate the
>> names, and add an 'and' b4 the last one, I imagine this is done
>> frequently?
>>
>> Thanks,
>> Wendy
>>
> 

-- 
Joseph Spiros
iThink Software
joseph.spi...@ithinksw.com
+1 (440) 707-6855

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

2010-08-11 Thread Joseph Spiros
You'll want to loop through the objects and print the appropriate
property of the objects that consists of just the name. Here's some
template code that does that, and also separates with commas and "and",
using a serial comma (aka Oxford comma).

(This assumes that your Filmmaker model has a "name" property/field)

{% with film.filmmakers.all as filmmakers %}{% for filmmaker in
filmmakers %}{% if filmmakers|length > 2 and not forloop.first %}, {%
endif %}{% if forloop.last and not forloop.first %} and {% endif %}{{
filmmaker.name }}{% endfor %}

Hope that helps!

On 8/11/10 3:53 PM, Wendy wrote:
> Hello,
> I'm just getting started, and I'm returning a many to many object in
> my template:
> 
> p>{{ film.filmmakers.all }}
> 
> So it's displaying the list:
> 
> [, ]
> 
> Can anyone tell me how to return just a string of the names?
> I'm still getting acclimated to python syntax.
> 
> Actually in a perfect world, it would be great to concatenate the
> names, and add an 'and' b4 the last one, I imagine this is done
> frequently?
> 
> Thanks,
> Wendy
> 

-- 
Joseph Spiros
iThink Software
joseph.spi...@ithinksw.com
+1 (440) 707-6855

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

2010-08-11 Thread Carlos Daniel Ruvalcaba Valenzuela
Use a for loop, there is tags to know if you are at the last item of
the list, so to not add the and:

{% for filmmaker in film.filmmakers.all %}
{{ filmmaker.name }} {% if not forloop.last %} and {% endif %}
{% endfor %}

Assuming you are using django 1.2, but you get the idea.

http://docs.djangoproject.com/en/1.2/ref/templates/builtins/#for

Regards,
Carlos Daniel Ruvalcaba Valenzuela

On Wed, Aug 11, 2010 at 12:53 PM, Wendy  wrote:
> Hello,
> I'm just getting started, and I'm returning a many to many object in
> my template:
>
> p>{{ film.filmmakers.all }}
>
> So it's displaying the list:
>
> [, ]
>
> Can anyone tell me how to return just a string of the names?
> I'm still getting acclimated to python syntax.
>
> Actually in a perfect world, it would be great to concatenate the
> names, and add an 'and' b4 the last one, I imagine this is done
> frequently?
>
> Thanks,
> Wendy
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Many to many ajax widget for admin

2010-08-02 Thread Carlos Ricardo Santos
Already tried to find a better approach without success, raw_id is now the
best option.

On 2 August 2010 10:54, Sævar Öfjörð  wrote:

> If someone is interested,
> I just used raw_id_fields in my intermediary inline modeladmin.
>
> class AuthorshipInline(admin.TabularInline):
>raw_id_fields = ('author',)
>
> This isn't exactly what I was going for, but it takes the really big
> select fields out of the picture.
>
> - Sævar
>
> On Jul 27, 5:24 am, ringemup  wrote:
> > You might want to check out grappelli and its Related Lookups feature:
> >
> > http://code.google.com/p/django-grappelli/
> >
> > On Jul 26, 4:30 pm, Sævar Öfjörð  wrote:
> >
> >
> >
> > > Hi
> >
> > > I have some models (Song and Author) that are related through an
> > > intermediary model (Authorship) like this:
> >
> > > class Song(models.Model)
> > > authors = models.ManyToManyField('Author', through='Authorship')
> >
> > > class Author(models.Model)
> > > name = models.CharField(max_length=255)
> >
> > > class Authorship(models.Model):
> > > AUTHORSHIP_TYPES = (
> > > ('lyrics', 'Lyrics'),
> > > ('melody', 'Melody'),
> > > ('cover', 'Cover'),
> > > )
> > > author = models.ForeignKey(Author)
> > > song = models.ForeignKey(Song)
> > > authorship_type = models.CharField(choices=AUTHORSHIP_TYPES)
> >
> > > I have inline editing set up in the admin for Song, so that
> > > authorships can be created/edited/deleted from the Song instance.
> > > But now the Authors have grown to about 2500 objects, which means that
> > > each select box contains 2500 options. This is too slow and I'm
> > > looking for an alternative.
> >
> > > I have come across Django Ajax Selects:
> http://code.google.com/p/django-ajax-selects/
> > > And Django Ajax Filtered Fields:
> http://code.google.com/p/django-ajax-filtered-fields/
> > > (actually I'm not sure if this can be used in the django admin)
> >
> > > But I haven't seen anything in their documentation about support for
> > > intermediary models like my Authorship model.
> >
> > > Has anyone had this problem and found a solution for it?
> >
> > > - Sævar
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>


-- 
Cumprimentos,
Carlos Ricardo Santos

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Many to many ajax widget for admin

2010-08-02 Thread Sævar Öfjörð
If someone is interested,
I just used raw_id_fields in my intermediary inline modeladmin.

class AuthorshipInline(admin.TabularInline):
raw_id_fields = ('author',)

This isn't exactly what I was going for, but it takes the really big
select fields out of the picture.

- Sævar

On Jul 27, 5:24 am, ringemup  wrote:
> You might want to check out grappelli and its Related Lookups feature:
>
> http://code.google.com/p/django-grappelli/
>
> On Jul 26, 4:30 pm, Sævar Öfjörð  wrote:
>
>
>
> > Hi
>
> > I have some models (Song and Author) that are related through an
> > intermediary model (Authorship) like this:
>
> > class Song(models.Model)
> >     authors = models.ManyToManyField('Author', through='Authorship')
>
> > class Author(models.Model)
> >     name = models.CharField(max_length=255)
>
> > class Authorship(models.Model):
> >         AUTHORSHIP_TYPES = (
> >                 ('lyrics', 'Lyrics'),
> >                 ('melody', 'Melody'),
> >                 ('cover', 'Cover'),
> >         )
> >         author = models.ForeignKey(Author)
> >         song = models.ForeignKey(Song)
> >         authorship_type = models.CharField(choices=AUTHORSHIP_TYPES)
>
> > I have inline editing set up in the admin for Song, so that
> > authorships can be created/edited/deleted from the Song instance.
> > But now the Authors have grown to about 2500 objects, which means that
> > each select box contains 2500 options. This is too slow and I'm
> > looking for an alternative.
>
> > I have come across Django Ajax 
> > Selects:http://code.google.com/p/django-ajax-selects/
> > And Django Ajax Filtered 
> > Fields:http://code.google.com/p/django-ajax-filtered-fields/
> > (actually I'm not sure if this can be used in the django admin)
>
> > But I haven't seen anything in their documentation about support for
> > intermediary models like my Authorship model.
>
> > Has anyone had this problem and found a solution for it?
>
> > - Sævar

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Many to many ajax widget for admin

2010-07-26 Thread ringemup

You might want to check out grappelli and its Related Lookups feature:

http://code.google.com/p/django-grappelli/


On Jul 26, 4:30 pm, Sævar Öfjörð  wrote:
> Hi
>
> I have some models (Song and Author) that are related through an
> intermediary model (Authorship) like this:
>
> class Song(models.Model)
>     authors = models.ManyToManyField('Author', through='Authorship')
>
> class Author(models.Model)
>     name = models.CharField(max_length=255)
>
> class Authorship(models.Model):
>         AUTHORSHIP_TYPES = (
>                 ('lyrics', 'Lyrics'),
>                 ('melody', 'Melody'),
>                 ('cover', 'Cover'),
>         )
>         author = models.ForeignKey(Author)
>         song = models.ForeignKey(Song)
>         authorship_type = models.CharField(choices=AUTHORSHIP_TYPES)
>
> I have inline editing set up in the admin for Song, so that
> authorships can be created/edited/deleted from the Song instance.
> But now the Authors have grown to about 2500 objects, which means that
> each select box contains 2500 options. This is too slow and I'm
> looking for an alternative.
>
> I have come across Django Ajax 
> Selects:http://code.google.com/p/django-ajax-selects/
> And Django Ajax Filtered 
> Fields:http://code.google.com/p/django-ajax-filtered-fields/
> (actually I'm not sure if this can be used in the django admin)
>
> But I haven't seen anything in their documentation about support for
> intermediary models like my Authorship model.
>
> Has anyone had this problem and found a solution for it?
>
> - Sævar

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Many-To-Many issue; trying to find a way around conditional id

2010-04-26 Thread Nick Serra
Can you be more clear on the exact result you're trying to achieve? Do
you want to see, for a given high school, how many recruit objects are
foreign keyed to it?

On Apr 26, 7:38 am, Nuno Maltez  wrote:
> Are you saying that:
>
> collegelist = 
> college.current_objects.filter(collegechoices__school=highschoolid).exclude 
> (name='Undeclared').distinct().annotate(ccount=Count('collegechoices'))
>
> gives you the same results as
>
> collegelist = 
> college.current_objects.exclude(name='Undeclared').distinct().annotate(ccou 
> nt=Count('collegechoices'))
>
> ?
>
> I don't think it should behave that way...
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Many-To-Many issue; trying to find a way around conditional id

2010-04-26 Thread Nuno Maltez
Are you saying that:

collegelist = 
college.current_objects.filter(collegechoices__school=highschoolid).exclude(name='Undeclared').distinct().annotate(ccount=Count('collegechoices'))

gives you the same results as

collegelist = 
college.current_objects.exclude(name='Undeclared').distinct().annotate(ccount=Count('collegechoices'))

?

I don't think it should behave that way...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Many-To-Many issue; trying to find a way around conditional id

2010-04-19 Thread Matt
Oops. That title should be "conditional if," of course.

On Apr 19, 2:43 pm, Matt  wrote:
> Hoping you all can tell me what I'm doing that's stupid here. I have
> three models:
>
> class highschool(models.Model):
>     name = models.CharField(max_length=50)
>     address = models.CharField(max_length=60)
>     city = models.CharField(max_length=60)
>     state = models.CharField(max_length=2)
>
> class college(models.Model):
>     name = models.CharField(max_length=75)
>     city = models.CharField(max_length=60)
>     state = models.CharField(max_length=2)
>     conference = models.ForeignKey(conference)
>     URL = models.URLField(verify_exists=True, max_length=200)
>
> class recruit(models.Model):
>     name = models.CharField(max_length = 100)
>     ...
>     school = models.ForeignKey(highschool)
>     colleges = models.ManyToManyField(college,
> related_name="collegechoices")
>
> What I'm trying to do is find out, for a given highschool: 1) What
> schools are after their recruits and 2) how many they're after.
>
> So far I've tried various iterations of something like:
>
> collegelist =
> college.current_objects.filter(collegechoices__school=highschoolid).exclude(name='Undeclared').distinct().annotate(ccount=Count('collegechoices'))
>
> Obviously, that doesn't work, as it counts up the total number of
> collegechoices without filtering for the highschool.
>
> I've seen some workarounds for the conditional if, but I have to think
> there's an easier way to skin this cat. Any ideas?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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

2010-04-14 Thread Francis Gulotta
I think that might be a better way, but the data should never change so I'm
ok with the denormalization. How would I access the po_num in that example?

Order.edi.po_num? or Order.PoNum.po_num?

I think though I was asking the wrong question. I updated this on Stack
Overflow.

What I really need to do is join the two tables so I can do a WHERE on a
> count of the related table. I would like to filter for all Order objects
> that have 0 related EDI856 objects.


At first I was thinking of putting a 'count' field in each model and having
the update logic in the overridden save() functions. This would have the
benefit of spending the computing costs up front instead of on every search
(there are a few hundred thousand records in each table). I imagine this is
a pretty common task but from Googling it seems there's no core django way
to do it, you just have to do it yourself. Is that correct?

I did find however another way to query for the counts using annotations.
http://docs.djangoproject.com/en/dev/topics/db/aggregation/#generating-aggregates-for-each-item-in-a-queryset

Annotations provide exactly the functionality I'm looking for so I'm going
to try them first, but something tells me adding the count field is the
right way to go.

-Francis

---
Francis Gulotta
wiz...@roborooter.com


2010/4/13 Ian Lewis 

> wizard,
>
> Would it make sense to use the intermediate table to hold the field?
>
> Using the stack overflow example:
>
> class Edi856(models.Model):
> pass
>
> class Order(models.Model):
> edi = models.ManyToManyField(Edi856, through='PoNum')
> def in_edi(self):
> '''Has the edi been processed?'''
> return self.edi.all().count()
>
> class PoNum(models.Model):
> order = models.ForeignKey(Order)
> edi = models.ForeignKey(Edi856)
> po_num = models.CharField(max_length=90, db_index=True )
>
>
> The save route also sounds ok, a pre_save signal could also work.
>
>
> On Wed, Apr 14, 2010 at 5:19 AM, wizard  wrote:
>
>> This is sort of an extension of my post from stackoverflow.
>>
>> http://stackoverflow.com/questions/2632573/how-do-i-relate-two-models-tables-in-django-based-on-non-primary-non-unique-keys
>>
>> The gist is I have two tables with a common field and I would like to
>> relate two models with a many to many based off of this field.
>>
>> As far as I can tell I have to build the relations manually. I was
>> thinking of overriding the save method in both models to query the
>> other table and rebuild the relation on save.
>>
>> Does this sound rational?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@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.
>>
>>
>
>
> --
> ===
> 株式会社ビープラウド  イアン・ルイス
> 〒150-0021
> 東京都渋谷区恵比寿西2-3-2 NSビル6階
> email: ianmle...@beproud.jp
> TEL:03-6416-9836
> FAX:03-6416-9837
> http://www.beproud.jp/
> ===
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>

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

2010-04-13 Thread Ian Lewis
wizard,

Would it make sense to use the intermediate table to hold the field?

Using the stack overflow example:

class Edi856(models.Model):
pass

class Order(models.Model):
edi = models.ManyToManyField(Edi856, through='PoNum')
def in_edi(self):
'''Has the edi been processed?'''
return self.edi.all().count()

class PoNum(models.Model):
order = models.ForeignKey(Order)
edi = models.ForeignKey(Edi856)
po_num = models.CharField(max_length=90, db_index=True )


The save route also sounds ok, a pre_save signal could also work.


On Wed, Apr 14, 2010 at 5:19 AM, wizard  wrote:

> This is sort of an extension of my post from stackoverflow.
>
> http://stackoverflow.com/questions/2632573/how-do-i-relate-two-models-tables-in-django-based-on-non-primary-non-unique-keys
>
> The gist is I have two tables with a common field and I would like to
> relate two models with a many to many based off of this field.
>
> As far as I can tell I have to build the relations manually. I was
> thinking of overriding the save method in both models to query the
> other table and rebuild the relation on save.
>
> Does this sound rational?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>


-- 
===
株式会社ビープラウド  イアン・ルイス
〒150-0021
東京都渋谷区恵比寿西2-3-2 NSビル6階
email: ianmle...@beproud.jp
TEL:03-6416-9836
FAX:03-6416-9837
http://www.beproud.jp/
===

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

2010-03-23 Thread TheIvIaxx
yes, this util helped a lot!  300 down to 20 i think.  I had a SQL
query ready, but then you lose all the ORM goodness.

I would think this should be part of the ORM, no?

In the SQL, I just had to add another join to the query generated by
the select_related() method.  The problem is you get duplicates back,
in that the image object rows are the same except for a term id:


| ID | FILE| TERM ID   |

| 1  | image.jpg |1   |
| 1  | image.jpg |2   |


Then you would just have to make a list out of the TERM IDs.

Anyhow, problem solved.  Thanks!

On Mar 18, 12:42 am, koenb  wrote:
> Take a look at something like django-selectreverse [1] for inspiration
> on how to reduce your querycount for M2M relations.
>
> Koen
>
> [1]http://code.google.com/p/django-selectreverse/
>
> On 17 mrt, 18:55, TheIvIaxx  wrote:
>
>
>
> > I made a mistake in my model definitions above.  The Term field on
> > Image is a ManyToMany() not ForeignKey().
>
> > Anyhow I did look into value_list, however it didn't add much, if any,
> > performance gain.  But the select_related did!  That was exactly what
> > I needed.  Thanks Bruno for the tip.
>
> > On Mar 17, 1:38 am, bruno desthuilliers
>
> >  wrote:
> > > On Mar 17, 4:24 am, TheIvIaxx  wrote:
>
> > > > Hello all, i have a question about a certain query i have.  Here is my
> > > > model setup:
>
> > > > class Term():
> > > >     term = CharField()
>
> > > > class Image():
> > > >     image = FileField()
> > > >     terms = ForeignKey(Term)
>
> > > > These have been abbreviated for simiplicity, ut you get the gist of
> > > > it.  Anyhow i have to query for a few hundred Image objects, then get
> > > > a list of Term objects for each of these.  Really i just need the IDs
> > > > of the Terms.  Currently i have my query like this:
>
> > > > images = Image.objects.all()
>
> > > you can use 'select_related' here - it'll use a join to prefetch
> > > related Term objects:
>
> > > images = Image.objects.select_related('terms').all()
>
> > > > responseImages = []
> > > > for i in images:
> > > >     terms = [term.id for term in n.terms.all()]
> > > >     responseObjects.append({'image': n, 'terms': terms})
>
> > > I guess this is not your real code !-)
>
> > > I don't know what this 'responseObjects' is - , but if you use Django
> > > templates, you just don't need all this above code. Just pass 'images'
> > > in the template's context and you'll be fine:
>
> > > 
> > > {% for image in images %}
> > >    
> > >       {{ image.title }}
> > >      
> > >         {% for term in image.terms.all %}
> > >             {{ term.id }}
> > >         {% endfor %}
> > >         
> > >    
> > > {% endfor %}
> > > 
>
> > > HTH

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

2010-03-23 Thread TheIvIaxx
as far as I could tell, select_related did not follow m2m
relationships, only FK.

On Mar 18, 2:12 am, bruno desthuilliers
 wrote:
> On Mar 18, 8:42 am, koenb  wrote:
>
> > Take a look at something like django-selectreverse [1] for inspiration
> > on how to reduce your querycount for M2M relations.
>
> > Koen
>
> > [1]http://code.google.com/p/django-selectreverse/
>
> I must be missing the point, but it looks seriously like reinventing
> the wheel ? How is it better than using select_related ???

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

2010-03-19 Thread Sam Walters
Yes, this conversation hits the nail on the head.

'select related' only works with forward facing keys.

http://code.google.com/p/django-selectreverse/ is a resonably good
piece of code to improve performance:

using a structure like:

class model1(model.Models)   1<* class model2(model.Models)
model1
= models.foreignkey(model1)
1<* class
model3(model.Models)
model1
= models.foreignkey(model1)
etc...

where your view/template code is:

for x in model1.objects.all()
#stuff
for y in x.model2_set.all()
#stuff
for y in x.model3_set.all()
#stuff

Gets awfully slow as you add modelX_set.all or scale it up to thousands of rows.

eg:
where model1 is 945 rows in the sql db:

time taken:  1.023
SQL queries:  1883

using select related:

time taken:  0.493
SQL queries:  21

I have not tried select related performance where there may be another
model with a reverse foreignkey facing model2.
I don't know how well it will face a multi level reverse foreign
key/many to many db structure.

Also don't forget to look at indexing for certain fields where
appropriate it can be a good performance improver:

http://docs.djangoproject.com/en/1.1/ref/models/fields/#db-index

cheers
sam_w




On Fri, Mar 19, 2010 at 5:15 AM, koenb  wrote:
> On 18 mrt, 10:12, bruno desthuilliers 
> wrote:
>> On Mar 18, 8:42 am, koenb  wrote:
>>
>> > Take a look at something like django-selectreverse [1] for inspiration
>> > on how to reduce your querycount for M2M relations.
>>
>> > Koen
>>
>> > [1]http://code.google.com/p/django-selectreverse/
>>
>> I must be missing the point, but it looks seriously like reinventing
>> the wheel ? How is it better than using select_related ???
>
> Select_related only populates forward one-to-many relationships
> (foreignkeys).
> It does not work for many-to-many relationships or reverse one-to-many
> relationships (the XX_set descriptors on the other side of fk's).
> You can not load those in one and the same query, but you can load all
> those objects in one single query instead of N extra queries.
> That is what selectreverse helps you to do. Look at the example on the
> introduction page of the project to see what kind of queries I mean.
>
> Koen
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@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.
>
>

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

2010-03-18 Thread koenb
On 18 mrt, 10:12, bruno desthuilliers 
wrote:
> On Mar 18, 8:42 am, koenb  wrote:
>
> > Take a look at something like django-selectreverse [1] for inspiration
> > on how to reduce your querycount for M2M relations.
>
> > Koen
>
> > [1]http://code.google.com/p/django-selectreverse/
>
> I must be missing the point, but it looks seriously like reinventing
> the wheel ? How is it better than using select_related ???

Select_related only populates forward one-to-many relationships
(foreignkeys).
It does not work for many-to-many relationships or reverse one-to-many
relationships (the XX_set descriptors on the other side of fk's).
You can not load those in one and the same query, but you can load all
those objects in one single query instead of N extra queries.
That is what selectreverse helps you to do. Look at the example on the
introduction page of the project to see what kind of queries I mean.

Koen

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

2010-03-18 Thread bruno desthuilliers


On Mar 18, 8:42 am, koenb  wrote:
> Take a look at something like django-selectreverse [1] for inspiration
> on how to reduce your querycount for M2M relations.
>
> Koen
>
> [1]http://code.google.com/p/django-selectreverse/
>

I must be missing the point, but it looks seriously like reinventing
the wheel ? How is it better than using select_related ???

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

2010-03-18 Thread bruno desthuilliers

On Mar 17, 6:55 pm, TheIvIaxx  wrote:
> I made a mistake in my model definitions above.

And a couple errors in the "view" code snippet too FWIW !-)

>  The Term field on
> Image is a ManyToMany() not ForeignKey().
>
> Anyhow I did look into value_list, however it didn't add much, if any,
> performance gain.

value_list is mostly useful to avoid loading full model instances when
you only want a couple attributes. You won't probably notice the gain
on a 300 items set on your dev server, but when it comes to queries
returning thousand times more items on an production server, it can
really make a difference. But anyway - I mostly mentioned this because
it does exactly the same thing as your raw SQL query.

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

2010-03-18 Thread koenb
Take a look at something like django-selectreverse [1] for inspiration
on how to reduce your querycount for M2M relations.

Koen

[1] http://code.google.com/p/django-selectreverse/



On 17 mrt, 18:55, TheIvIaxx  wrote:
> I made a mistake in my model definitions above.  The Term field on
> Image is a ManyToMany() not ForeignKey().
>
> Anyhow I did look into value_list, however it didn't add much, if any,
> performance gain.  But the select_related did!  That was exactly what
> I needed.  Thanks Bruno for the tip.
>
> On Mar 17, 1:38 am, bruno desthuilliers
>
>  wrote:
> > On Mar 17, 4:24 am, TheIvIaxx  wrote:
>
> > > Hello all, i have a question about a certain query i have.  Here is my
> > > model setup:
>
> > > class Term():
> > >     term = CharField()
>
> > > class Image():
> > >     image = FileField()
> > >     terms = ForeignKey(Term)
>
> > > These have been abbreviated for simiplicity, ut you get the gist of
> > > it.  Anyhow i have to query for a few hundred Image objects, then get
> > > a list of Term objects for each of these.  Really i just need the IDs
> > > of the Terms.  Currently i have my query like this:
>
> > > images = Image.objects.all()
>
> > you can use 'select_related' here - it'll use a join to prefetch
> > related Term objects:
>
> > images = Image.objects.select_related('terms').all()
>
> > > responseImages = []
> > > for i in images:
> > >     terms = [term.id for term in n.terms.all()]
> > >     responseObjects.append({'image': n, 'terms': terms})
>
> > I guess this is not your real code !-)
>
> > I don't know what this 'responseObjects' is - , but if you use Django
> > templates, you just don't need all this above code. Just pass 'images'
> > in the template's context and you'll be fine:
>
> > 
> > {% for image in images %}
> >    
> >       {{ image.title }}
> >      
> >         {% for term in image.terms.all %}
> >             {{ term.id }}
> >         {% endfor %}
> >         
> >    
> > {% endfor %}
> > 
>
> > HTH

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

2010-03-17 Thread TheIvIaxx
I made a mistake in my model definitions above.  The Term field on
Image is a ManyToMany() not ForeignKey().

Anyhow I did look into value_list, however it didn't add much, if any,
performance gain.  But the select_related did!  That was exactly what
I needed.  Thanks Bruno for the tip.


On Mar 17, 1:38 am, bruno desthuilliers
 wrote:
> On Mar 17, 4:24 am, TheIvIaxx  wrote:
>
>
>
>
>
> > Hello all, i have a question about a certain query i have.  Here is my
> > model setup:
>
> > class Term():
> >     term = CharField()
>
> > class Image():
> >     image = FileField()
> >     terms = ForeignKey(Term)
>
> > These have been abbreviated for simiplicity, ut you get the gist of
> > it.  Anyhow i have to query for a few hundred Image objects, then get
> > a list of Term objects for each of these.  Really i just need the IDs
> > of the Terms.  Currently i have my query like this:
>
> > images = Image.objects.all()
>
> you can use 'select_related' here - it'll use a join to prefetch
> related Term objects:
>
> images = Image.objects.select_related('terms').all()
>
>
>
> > responseImages = []
> > for i in images:
> >     terms = [term.id for term in n.terms.all()]
> >     responseObjects.append({'image': n, 'terms': terms})
>
> I guess this is not your real code !-)
>
> I don't know what this 'responseObjects' is - , but if you use Django
> templates, you just don't need all this above code. Just pass 'images'
> in the template's context and you'll be fine:
>
> 
> {% for image in images %}
>    
>       {{ image.title }}
>      
>         {% for term in image.terms.all %}
>             {{ term.id }}
>         {% endfor %}
>         
>    
> {% endfor %}
> 
>
> HTH

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

2010-03-17 Thread bruno desthuilliers
On Mar 17, 4:37 am, TheIvIaxx  wrote:
> i suppose i could, but that will be a last resort :)  What about
> dropping down to raw SQL just to get the IDs:
>
> SELECT term_id FROM image_term WHERE image_id = %i
>
> or is that discouraged?  Can it be done with the ORM?

You'd have the exact same result using the ORM:

   ids = image.terms.values_list('id', flat=True)

but this won't solve the real problem of doing images.count() queries
- which is what select_related is for.

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

2010-03-17 Thread bruno desthuilliers
On Mar 17, 4:24 am, TheIvIaxx  wrote:
> Hello all, i have a question about a certain query i have.  Here is my
> model setup:
>
> class Term():
>     term = CharField()
>
> class Image():
>     image = FileField()
>     terms = ForeignKey(Term)
>
> These have been abbreviated for simiplicity, ut you get the gist of
> it.  Anyhow i have to query for a few hundred Image objects, then get
> a list of Term objects for each of these.  Really i just need the IDs
> of the Terms.  Currently i have my query like this:
>
> images = Image.objects.all()

you can use 'select_related' here - it'll use a join to prefetch
related Term objects:

images = Image.objects.select_related('terms').all()

>
> responseImages = []
> for i in images:
>     terms = [term.id for term in n.terms.all()]
>     responseObjects.append({'image': n, 'terms': terms})

I guess this is not your real code !-)



I don't know what this 'responseObjects' is - , but if you use Django
templates, you just don't need all this above code. Just pass 'images'
in the template's context and you'll be fine:


{% for image in images %}
   
  {{ image.title }}
 
{% for term in image.terms.all %}
{{ term.id }}
{% endfor %}

   
{% endfor %}



HTH

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

2010-03-16 Thread Kenneth Gonsalves
On Wednesday 17 Mar 2010 9:07:47 am TheIvIaxx wrote:
> i suppose i could, but that will be a last resort :)  What about
> dropping down to raw SQL just to get the IDs:
> 
> SELECT term_id FROM image_term WHERE image_id = %i
> 
> or is that discouraged?  Can it be done with the ORM?
> 

look at 'get_values' and 'flat'
-- 
regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS
http://certificate.nrcfoss.au-kbc.org.in

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

2010-03-16 Thread aditya
You can, and I'd be interested to know how much of a speedup that
gives. Here's the relevant page on writing raw SQL:
http://docs.djangoproject.com/en/dev/topics/db/sql/

If you know SQL (and it looks like you do) it should be familiar
territory. The interesting bits are deferring fields, and adding
annotations...maybe those could help speed up your query?


Aditya


On Mar 16, 10:37 pm, TheIvIaxx  wrote:
> i suppose i could, but that will be a last resort :)  What about
> dropping down to raw SQL just to get the IDs:
>
> SELECT term_id FROM image_term WHERE image_id = %i
>
> or is that discouraged?  Can it be done with the ORM?
>
> On Mar 16, 8:32 pm, aditya  wrote:
>
> > Is there any way you could reduce the # of images to return? Another
> > thing you could do is cache this info so you don't have to do it
> > multiple times.
>
> > Aditya
>
> > On Mar 16, 10:24 pm, TheIvIaxx  wrote:
>
> > > Hello all, i have a question about a certain query i have.  Here is my
> > > model setup:
>
> > > class Term():
> > >     term = CharField()
>
> > > class Image():
> > >     image = FileField()
> > >     terms = ForeignKey(Term)
>
> > > These have been abbreviated for simiplicity, ut you get the gist of
> > > it.  Anyhow i have to query for a few hundred Image objects, then get
> > > a list of Term objects for each of these.  Really i just need the IDs
> > > of the Terms.  Currently i have my query like this:
>
> > > images = Image.objects.all()
>
> > > responseImages = []
> > > for i in images:
> > >     terms = [term.id for term in n.terms.all()]
> > >     responseObjects.append({'image': n, 'terms': terms})
>
> > > Am i losing some efficiency here?  Seems like a fairly common
> > > operation, but I think each of the list comprehensions is a db hit.
> > > on ~300 objects, thats a lot of queries.
>
> > > Any advice on this one?
>
> > > 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-us...@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: Many to Many...so many queries

2010-03-16 Thread TheIvIaxx
i suppose i could, but that will be a last resort :)  What about
dropping down to raw SQL just to get the IDs:

SELECT term_id FROM image_term WHERE image_id = %i

or is that discouraged?  Can it be done with the ORM?

On Mar 16, 8:32 pm, aditya  wrote:
> Is there any way you could reduce the # of images to return? Another
> thing you could do is cache this info so you don't have to do it
> multiple times.
>
> Aditya
>
> On Mar 16, 10:24 pm, TheIvIaxx  wrote:
>
>
>
> > Hello all, i have a question about a certain query i have.  Here is my
> > model setup:
>
> > class Term():
> >     term = CharField()
>
> > class Image():
> >     image = FileField()
> >     terms = ForeignKey(Term)
>
> > These have been abbreviated for simiplicity, ut you get the gist of
> > it.  Anyhow i have to query for a few hundred Image objects, then get
> > a list of Term objects for each of these.  Really i just need the IDs
> > of the Terms.  Currently i have my query like this:
>
> > images = Image.objects.all()
>
> > responseImages = []
> > for i in images:
> >     terms = [term.id for term in n.terms.all()]
> >     responseObjects.append({'image': n, 'terms': terms})
>
> > Am i losing some efficiency here?  Seems like a fairly common
> > operation, but I think each of the list comprehensions is a db hit.
> > on ~300 objects, thats a lot of queries.
>
> > Any advice on this one?
>
> > 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-us...@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: Many to Many...so many queries

2010-03-16 Thread aditya
Is there any way you could reduce the # of images to return? Another
thing you could do is cache this info so you don't have to do it
multiple times.

Aditya

On Mar 16, 10:24 pm, TheIvIaxx  wrote:
> Hello all, i have a question about a certain query i have.  Here is my
> model setup:
>
> class Term():
>     term = CharField()
>
> class Image():
>     image = FileField()
>     terms = ForeignKey(Term)
>
> These have been abbreviated for simiplicity, ut you get the gist of
> it.  Anyhow i have to query for a few hundred Image objects, then get
> a list of Term objects for each of these.  Really i just need the IDs
> of the Terms.  Currently i have my query like this:
>
> images = Image.objects.all()
>
> responseImages = []
> for i in images:
>     terms = [term.id for term in n.terms.all()]
>     responseObjects.append({'image': n, 'terms': terms})
>
> Am i losing some efficiency here?  Seems like a fairly common
> operation, but I think each of the list comprehensions is a db hit.
> on ~300 objects, thats a lot of queries.
>
> Any advice on this one?
>
> 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-us...@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: Many-To-Many Relationship with intermediate table

2010-03-07 Thread Dennis Kaarsemaker
On zo, 2010-03-07 at 05:01 -0800, jorge.silva wrote:
> Hi there!
> 
> As far as I've read in the Django wiki this is a very common
> situation, yet I can't get it right
> I've inherited a legacy database which I'm slowly trying to model in
> Django to benefit from the free Admin site. As long as I'm here I'm
> also trying to learn something ;)
> 
> My situation is as follows: I have two tables, 'Legislation' and
> 'Revoked'. The first contains data about a given legislation (name,
> date, etc) while the later only contains two attributes
> (id_revoked, id_legislation) both of which are FK's to 'Legislation'.
> 
>
> If a Legislation appears in the Revoked relation by id_revoked it
> simply means it is Revoked by id_legislation. If on the contrary it is
> referenced by id_legislation it means it revokes id_revoked.
> 
> I'm trying to model this case in Django but I'm not getting it. Can
> you help me?
> Thanks in advance.

What your tables contain is what django calls a ManyToManyField. You
will need to specify a through model manually as you use different
column names than what django would use automatically. Something like
this should do the trick:

class Legislation(model.Model):
revoked = models.ManyToManyField('self', through='Revoked')

class Revoked(models.Model):
revoked = models.ForeignKey(Legislation, db_column='id_revoked')
legislation = models.ForeignKey(Legislation, db_column='id_legislation)

-- 
Dennis K.

The universe tends towards maximum irony. Don't push it.

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

2009-11-28 Thread Jonathan
The BusinessVersion isn't relevant, I posted the whole model to put it
in context. It's a web app to track software through the software
development lifecycle.

Regardless of the lifecyle stage (development, test, production), all
instances of an application consist of the same Group of packages
(python, django). What differs during the lifecycle stages are the
PackageVersion's.

The Group is a generic placeholder to indicate what Package's should
be included in the Profile. The Profile needs to adapt to changes, so
if another Package is added to a Group then all existing Profile's
automatically prompt for the new Package.

I've been reading a bit and perhaps model inheritance is what I'm
after. A VersionedPackage (renamed from PackageVersion) is really just
a Package with an extra field. Does that sound right?

Jonathan


On Nov 29, 2:31 am, t0ster  wrote:
> May be Group should include packages of specific versions:
>
> class Group(models.Model):
>     name = models.CharField(max_length=100)
>     product = models.ForeignKey(Product)
>     -packages = models.ManyToManyField(Package)
>     +packages = models.ManyToManyField(PackageVersion)
>
> class Profile(models.Model):
>     name = models.CharField(max_length=100)
>     businessversion = models.ForeignKey(BusinessVersion)
>     lifecyclestage = models.ForeignKey(LifecycleStage)
>     group = models.ForeignKey(Group)
>     -packageversions = models.ManyToManyField(PackageVersion)
>
> So:
>
> for package in profile.profile.group.packages.all():
>     print package.package.name
>     print package.version
>
> And what is BusinessVersion I didn't understand.
>
> On Nov 28, 4:59 pm, Jonathan  wrote:
>
> > Hi,
>
> > I've slimmed it down to the relevant fields. I'm a bit of a noob, but
> > I think I'm basically trying to build a generic framework that can be
> > made specific in a profile.
>
> > Profile = BusinessVersion + Group + LifecycleStage + Package.Versions
>
> > Jonathan
>
> > class Product(models.Model):
> >     name = models.CharField(max_length=20)
>
> > class BusinessVersion(models.Model):
> >     version = models.CharField(max_length=10)
> >     description = models.CharField(max_length=100)
> >     product = models.ForeignKey(Product)
>
> > class LifecycleStage(models.Model):
> >     name = models.CharField(max_length=40)
> >     sequence = models.DecimalField(max_digits=2, decimal_places=0)
>
> > class Package(models.Model):
> >     name = models.CharField(max_length=100)
>
> > class PackageVersion(models.Model):
> >     version = models.CharField(max_length=10)
> >     package = models.ForeignKey(Package)
> >     lifecyclestage = models.ForeignKey(LifecycleStage)
>
> > class Group(models.Model):
> >     name = models.CharField(max_length=100)
> >     product = models.ForeignKey(Product)
> >     packages = models.ManyToManyField(Package)
>
> > class Profile(models.Model):
> >     name = models.CharField(max_length=100)
> >     businessversion = models.ForeignKey(BusinessVersion)
> >     lifecyclestage = models.ForeignKey(LifecycleStage)
> >     group = models.ForeignKey(Group)
> >     packageversions = models.ManyToManyField(PackageVersion)
>
> > class Stream(models.Model):
> >     name = models.CharField(max_length=4)
> >     businessversion = models.ForeignKey(BusinessVersion)
>
> > On Nov 29, 1:19 am, t0ster  wrote:
>
> > > Could you post your models.py code here?
>
> > > On Nov 28, 1:10 pm, Jonathan  wrote:
>
> > > > This may be more of a general database design question, but I want to
> > > > come up with something that works with Django's ORM.
>
> > > > I have four bits of information that I want to link together. Generic
> > > > packages, package versions, groups of packages and a profile that
> > > > brings them together.
>
> > > > The final goal is a Profile that binds the Packages from a Group to
> > > > specific Versions.
>
> > > > I have a solution at the moment but it seems a bit clumsy for what
> > > > seems like something that would be commonly encountered.
>
> > > > 4 models: Package, Version, Group and Profile. I've omitted the id
> > > > primary key column on the examples.
>
> > > > Package:
> > > > | name   |
> > > > --
> > > > | django |
> > > > | python |
>
> > > > Version:
> > > > | package_id | version |
> > > > --
> > > > |          1 |     1.0 |
> > > > |          1 |     1.1 |
> > > > |          2 |     2.4 |
> > > > |          2 |     2.6 |
>
> > > > Group:
> > > > | name |
> > > > --
> > > > | django_stack |
>
> > > > group_packages:
> > > > | group_id | package_id |
> > > > --
> > > > |        1 |          1 |
> > > > |        1 |          2 |
>
> > > > Profile:
> > > > |        name | group_id |
> > > > --
> > > > | django_prod |        1 |
> > > > |  django_dev |        1 |
>
> > > > profile_packageversion:
> > > > | profile_id | version_id |
> > > > --
> > > > |          1 |          1 |
> > > > |          1 |          2 |
> > > > |          2 |          3 |
> > > > |          2 |          4 |
>
> > > > I can get 

Re: Many-to-many through multiple tables

2009-11-28 Thread t0ster
May be Group should include packages of specific versions:

class Group(models.Model):
name = models.CharField(max_length=100)
product = models.ForeignKey(Product)
-packages = models.ManyToManyField(Package)
+packages = models.ManyToManyField(PackageVersion)


class Profile(models.Model):
name = models.CharField(max_length=100)
businessversion = models.ForeignKey(BusinessVersion)
lifecyclestage = models.ForeignKey(LifecycleStage)
group = models.ForeignKey(Group)
-packageversions = models.ManyToManyField(PackageVersion)

So:

for package in profile.profile.group.packages.all():
print package.package.name
print package.version


And what is BusinessVersion I didn't understand.


On Nov 28, 4:59 pm, Jonathan  wrote:
> Hi,
>
> I've slimmed it down to the relevant fields. I'm a bit of a noob, but
> I think I'm basically trying to build a generic framework that can be
> made specific in a profile.
>
> Profile = BusinessVersion + Group + LifecycleStage + Package.Versions
>
> Jonathan
>
> class Product(models.Model):
>     name = models.CharField(max_length=20)
>
> class BusinessVersion(models.Model):
>     version = models.CharField(max_length=10)
>     description = models.CharField(max_length=100)
>     product = models.ForeignKey(Product)
>
> class LifecycleStage(models.Model):
>     name = models.CharField(max_length=40)
>     sequence = models.DecimalField(max_digits=2, decimal_places=0)
>
> class Package(models.Model):
>     name = models.CharField(max_length=100)
>
> class PackageVersion(models.Model):
>     version = models.CharField(max_length=10)
>     package = models.ForeignKey(Package)
>     lifecyclestage = models.ForeignKey(LifecycleStage)
>
> class Group(models.Model):
>     name = models.CharField(max_length=100)
>     product = models.ForeignKey(Product)
>     packages = models.ManyToManyField(Package)
>
> class Profile(models.Model):
>     name = models.CharField(max_length=100)
>     businessversion = models.ForeignKey(BusinessVersion)
>     lifecyclestage = models.ForeignKey(LifecycleStage)
>     group = models.ForeignKey(Group)
>     packageversions = models.ManyToManyField(PackageVersion)
>
> class Stream(models.Model):
>     name = models.CharField(max_length=4)
>     businessversion = models.ForeignKey(BusinessVersion)
>
> On Nov 29, 1:19 am, t0ster  wrote:
>
>
>
> > Could you post your models.py code here?
>
> > On Nov 28, 1:10 pm, Jonathan  wrote:
>
> > > This may be more of a general database design question, but I want to
> > > come up with something that works with Django's ORM.
>
> > > I have four bits of information that I want to link together. Generic
> > > packages, package versions, groups of packages and a profile that
> > > brings them together.
>
> > > The final goal is a Profile that binds the Packages from a Group to
> > > specific Versions.
>
> > > I have a solution at the moment but it seems a bit clumsy for what
> > > seems like something that would be commonly encountered.
>
> > > 4 models: Package, Version, Group and Profile. I've omitted the id
> > > primary key column on the examples.
>
> > > Package:
> > > | name   |
> > > --
> > > | django |
> > > | python |
>
> > > Version:
> > > | package_id | version |
> > > --
> > > |          1 |     1.0 |
> > > |          1 |     1.1 |
> > > |          2 |     2.4 |
> > > |          2 |     2.6 |
>
> > > Group:
> > > | name |
> > > --
> > > | django_stack |
>
> > > group_packages:
> > > | group_id | package_id |
> > > --
> > > |        1 |          1 |
> > > |        1 |          2 |
>
> > > Profile:
> > > |        name | group_id |
> > > --
> > > | django_prod |        1 |
> > > |  django_dev |        1 |
>
> > > profile_packageversion:
> > > | profile_id | version_id |
> > > --
> > > |          1 |          1 |
> > > |          1 |          2 |
> > > |          2 |          3 |
> > > |          2 |          4 |
>
> > > I can get what I need from a two step process, but is this the best or
> > > most direct way to achieve this?
>
> > > for package in profile.group.packages.all():
> > >     print package.name
> > >     for version in package.versions.all():
> > >         print version
>
> > > Is there a nicer way to do this? Is there a different model structure
> > > that I could use?
>
> > > Jonathan

--

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

2009-11-28 Thread Jonathan
Hi,

I've slimmed it down to the relevant fields. I'm a bit of a noob, but
I think I'm basically trying to build a generic framework that can be
made specific in a profile.

Profile = BusinessVersion + Group + LifecycleStage + Package.Versions

Jonathan

class Product(models.Model):
name = models.CharField(max_length=20)

class BusinessVersion(models.Model):
version = models.CharField(max_length=10)
description = models.CharField(max_length=100)
product = models.ForeignKey(Product)

class LifecycleStage(models.Model):
name = models.CharField(max_length=40)
sequence = models.DecimalField(max_digits=2, decimal_places=0)

class Package(models.Model):
name = models.CharField(max_length=100)

class PackageVersion(models.Model):
version = models.CharField(max_length=10)
package = models.ForeignKey(Package)
lifecyclestage = models.ForeignKey(LifecycleStage)

class Group(models.Model):
name = models.CharField(max_length=100)
product = models.ForeignKey(Product)
packages = models.ManyToManyField(Package)

class Profile(models.Model):
name = models.CharField(max_length=100)
businessversion = models.ForeignKey(BusinessVersion)
lifecyclestage = models.ForeignKey(LifecycleStage)
group = models.ForeignKey(Group)
packageversions = models.ManyToManyField(PackageVersion)

class Stream(models.Model):
name = models.CharField(max_length=4)
businessversion = models.ForeignKey(BusinessVersion)

On Nov 29, 1:19 am, t0ster  wrote:
> Could you post your models.py code here?
>
> On Nov 28, 1:10 pm, Jonathan  wrote:
>
> > This may be more of a general database design question, but I want to
> > come up with something that works with Django's ORM.
>
> > I have four bits of information that I want to link together. Generic
> > packages, package versions, groups of packages and a profile that
> > brings them together.
>
> > The final goal is a Profile that binds the Packages from a Group to
> > specific Versions.
>
> > I have a solution at the moment but it seems a bit clumsy for what
> > seems like something that would be commonly encountered.
>
> > 4 models: Package, Version, Group and Profile. I've omitted the id
> > primary key column on the examples.
>
> > Package:
> > | name   |
> > --
> > | django |
> > | python |
>
> > Version:
> > | package_id | version |
> > --
> > |          1 |     1.0 |
> > |          1 |     1.1 |
> > |          2 |     2.4 |
> > |          2 |     2.6 |
>
> > Group:
> > | name |
> > --
> > | django_stack |
>
> > group_packages:
> > | group_id | package_id |
> > --
> > |        1 |          1 |
> > |        1 |          2 |
>
> > Profile:
> > |        name | group_id |
> > --
> > | django_prod |        1 |
> > |  django_dev |        1 |
>
> > profile_packageversion:
> > | profile_id | version_id |
> > --
> > |          1 |          1 |
> > |          1 |          2 |
> > |          2 |          3 |
> > |          2 |          4 |
>
> > I can get what I need from a two step process, but is this the best or
> > most direct way to achieve this?
>
> > for package in profile.group.packages.all():
> >     print package.name
> >     for version in package.versions.all():
> >         print version
>
> > Is there a nicer way to do this? Is there a different model structure
> > that I could use?
>
> > Jonathan

--

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

2009-11-28 Thread t0ster
Could you post your models.py code here?

On Nov 28, 1:10 pm, Jonathan  wrote:
> This may be more of a general database design question, but I want to
> come up with something that works with Django's ORM.
>
> I have four bits of information that I want to link together. Generic
> packages, package versions, groups of packages and a profile that
> brings them together.
>
> The final goal is a Profile that binds the Packages from a Group to
> specific Versions.
>
> I have a solution at the moment but it seems a bit clumsy for what
> seems like something that would be commonly encountered.
>
> 4 models: Package, Version, Group and Profile. I've omitted the id
> primary key column on the examples.
>
> Package:
> | name   |
> --
> | django |
> | python |
>
> Version:
> | package_id | version |
> --
> |          1 |     1.0 |
> |          1 |     1.1 |
> |          2 |     2.4 |
> |          2 |     2.6 |
>
> Group:
> | name |
> --
> | django_stack |
>
> group_packages:
> | group_id | package_id |
> --
> |        1 |          1 |
> |        1 |          2 |
>
> Profile:
> |        name | group_id |
> --
> | django_prod |        1 |
> |  django_dev |        1 |
>
> profile_packageversion:
> | profile_id | version_id |
> --
> |          1 |          1 |
> |          1 |          2 |
> |          2 |          3 |
> |          2 |          4 |
>
> I can get what I need from a two step process, but is this the best or
> most direct way to achieve this?
>
> for package in profile.group.packages.all():
>     print package.name
>     for version in package.versions.all():
>         print version
>
> Is there a nicer way to do this? Is there a different model structure
> that I could use?
>
> Jonathan

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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: Many to many relation - parents without any children

2009-11-15 Thread Tomasz Zieliński


On 15 Lis, 09:34, Nagy Károly  wrote:
> Tomasz Zieli ski wrote:
> > How about something like this (should work, although I haven't checked
> > it):
>
> > Author.objects.annotate(article_num=Count('articles')).filter
> > (article_num=0)
>
> > - where articles=ManyToManyField('Article')
>
> This is so elegant, so i have to upgrade to 1.1 now... :)
>
> Thank you Tomasz
>

My pleasure. Upgrade should be straightforward and painless,
assuming you're on 1.0 now.

--
Tomasz Zieliński
http://pyconsultant.eu

--

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




Re: Many to many relation - parents without any children

2009-11-15 Thread Nagy Károly
Tomasz Zieliński wrote:
> How about something like this (should work, although I haven't checked
> it):
>
> Author.objects.annotate(article_num=Count('articles')).filter
> (article_num=0)
>
> - where articles=ManyToManyField('Article')
>   
This is so elegant, so i have to upgrade to 1.1 now... :)

Thank you Tomasz

Charlie.

--

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




Re: Many to many relation - parents without any children

2009-11-14 Thread Tomasz Zieliński


On 14 Lis, 23:20, Nagy Károly  wrote:
> Please help me in orm level filtering many-to-many relations.
>
> I have to filter all "authors" who does not belongs to any "articles".
> Or the opposite of this, list of orphaned articles...
>
> I dont want to write sql in the model if possible.

How about something like this (should work, although I haven't checked
it):

Author.objects.annotate(article_num=Count('articles')).filter
(article_num=0)

- where articles=ManyToManyField('Article')

--
Tomasz Zieliński
http://pyconsultant.eu

--

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




Re: many to many add by ids

2009-09-30 Thread Tom Evans

On Tue, 2009-09-29 at 16:16 -0700, rich.al...@gmail.com wrote:
> I have the following I'm trying to optimize.
> 
> Input (from the web) is
> 
> sids = "1,2,3,5"  (a list of ids is posted, say they are article ids)
> 
> Now, to add them to a many to many, I'd like to just
> 
> try:
> authors.articles.add(ids).
> except:
> 
> I know the ids need to be ints, but tried a number of things to get
> them into the proper format but all fail with one exception or another
> 
> ids = map(int, sids.split(','))
> 
> but i konw that:  authors.articles.add(1,2,3,4) workshow do i get
> "1,2,3,4" into 1,2,3,4
> 
> probably a simple python thing or something.
> 
> thanks
> (disregard the need for validation above).

Yep, pretty straightforward:

authors.articles.add(*map(int, sids.split(',')))

See
http://docs.python.org/tutorial/controlflow.html#tut-unpacking-arguments

Cheers

Tom


--~--~-~--~~~---~--~~
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: Many-to-many column admin interface

2009-08-30 Thread Thomas Guettler

Thank you for this link. Looks good

Sven Richter schrieb:
> Ah, and google does help or at least django_snippets.
> I found the solution here:
> http://www.djangosnippets.org/snippets/1295
> 
> The trick is to create a column in both models and in one with the option to
> not syncdb.
> Its really simple, just 6 lines at all.


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

--~--~-~--~~~---~--~~
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: Many-to-many column admin interface

2009-08-28 Thread Sven Richter
Yea, i thought about that, but for me this seems like an ugly workaround.
Dont misunderstand me, i dont know enough about django and its database
internals, but why should i use a third model for something i can access
directly?

The solution i posted above was exactly what i was looking for and what
seems logic to me, but i could of course be wrong too.


Greetings
Sven

On Fri, Aug 28, 2009 at 6:19 PM, patrickk  wrote:

>
> I could be mistaken ... but why not using a third model.
>
> C(models.model):
>   a = models.ForeignKey('A')
>   b = models.ForeignKey('B')
>
> when editing either A or B, you could use C as inlines.
>
> regards,
> patrick
>
>
> On 28 Aug., 17:18, Sven Richter  wrote:
> > But i wonder how this would help me further.
> > In the End it doesnt matter for me on which model i define the M2M
> relation.
> > But i need to access the M2M Table from both models, at least in the view
> or
> > in the template if not in the admin interface.
> >
> > I am having a hard time finding out how to achieve that.
> >
> > Any Ideas?
> >
> > Greetings
> > Sven
> >
> > On Fri, Aug 28, 2009 at 3:04 PM, Sven Richter  >wrote:
> >
> > > I've opened a bug/feature request at:
> > >http://code.djangoproject.com/ticket/11795#comment:2
> > > if someone is interested.
> >
> > > Greetings
> > > Sven
> >
> > > On Fri, Aug 28, 2009 at 6:59 AM, Craig McClanahan  >wrote:
> >
> > >> On Thu, Aug 27, 2009 at 10:00 AM, Sven Richter >
> > >> wrote:
> > >> > I found this thread:
> >
> > >>http://stackoverflow.com/questions/660260/django-admin-form-for-many-.
> ..
> > >> > on Stackoverflow, but when i try the suggested TabularInline thing i
> get
> > >> the
> > >> > error:
> >
> > >> >  has no ForeignKey to
> > >>  > >> > 'politlog.entry.models.Entries'>
> >
> > >> At least with Django 1.0.x, the admin interface does not support
> > >> many-to-many relationships on inlines -- it will always return an
> > >> error like the one you got above.  Indeed, the message is technically
> > >> accurate, because m2m relationships get implemented as a separate
> > >> table, so there is no direct relationship between the two.
> > >> InlineModelAdmin works great for one-to-many but not for many-to-many.
> >
> > >> I'd also be interested in solutions to this, not having found anything
> > >> in a bunch of Google searches.  The alternative I'm planning on is
> > >> having to hand-code some views, forms, and templates that let me do
> > >> the right thing -- not a huge amount of work, but having admin do it
> > >> for us would be way cool.
> >
> > >> Craig
> >
> > >> > Greetings
> > >> > Sven
> >
> >
> >
>

--~--~-~--~~~---~--~~
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: Many-to-many column admin interface

2009-08-28 Thread Sven Richter
But i wonder how this would help me further.
In the End it doesnt matter for me on which model i define the M2M relation.
But i need to access the M2M Table from both models, at least in the view or
in the template if not in the admin interface.

I am having a hard time finding out how to achieve that.

Any Ideas?


Greetings
Sven

On Fri, Aug 28, 2009 at 3:04 PM, Sven Richter wrote:

> I've opened a bug/feature request at:
> http://code.djangoproject.com/ticket/11795#comment:2
> if someone is interested.
>
>
> Greetings
> Sven
>
>
> On Fri, Aug 28, 2009 at 6:59 AM, Craig McClanahan wrote:
>
>>
>> On Thu, Aug 27, 2009 at 10:00 AM, Sven Richter
>> wrote:
>> > I found this thread:
>> >
>> http://stackoverflow.com/questions/660260/django-admin-form-for-many-to-many-relationship
>> > on Stackoverflow, but when i try the suggested TabularInline thing i get
>> the
>> > error:
>> >
>> >  has no ForeignKey to
>> > > 'politlog.entry.models.Entries'>
>> >
>>
>> At least with Django 1.0.x, the admin interface does not support
>> many-to-many relationships on inlines -- it will always return an
>> error like the one you got above.  Indeed, the message is technically
>> accurate, because m2m relationships get implemented as a separate
>> table, so there is no direct relationship between the two.
>> InlineModelAdmin works great for one-to-many but not for many-to-many.
>>
>> I'd also be interested in solutions to this, not having found anything
>> in a bunch of Google searches.  The alternative I'm planning on is
>> having to hand-code some views, forms, and templates that let me do
>> the right thing -- not a huge amount of work, but having admin do it
>> for us would be way cool.
>>
>> Craig
>>
>>
>> > Greetings
>> > Sven
>>
>> >>
>>
>

--~--~-~--~~~---~--~~
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: Many-to-many column admin interface

2009-08-28 Thread Sven Richter
Ah, and google does help or at least django_snippets.
I found the solution here:
http://www.djangosnippets.org/snippets/1295

The trick is to create a column in both models and in one with the option to
not syncdb.
Its really simple, just 6 lines at all.


Greetings and a nice Weekend
Sven

On Fri, Aug 28, 2009 at 5:18 PM, Sven Richter wrote:

> But i wonder how this would help me further.
> In the End it doesnt matter for me on which model i define the M2M
> relation.
> But i need to access the M2M Table from both models, at least in the view
> or in the template if not in the admin interface.
>
> I am having a hard time finding out how to achieve that.
>
> Any Ideas?
>
>
> Greetings
> Sven
>
>
> On Fri, Aug 28, 2009 at 3:04 PM, Sven Richter wrote:
>
>> I've opened a bug/feature request at:
>> http://code.djangoproject.com/ticket/11795#comment:2
>> if someone is interested.
>>
>>
>> Greetings
>> Sven
>>
>>
>> On Fri, Aug 28, 2009 at 6:59 AM, Craig McClanahan wrote:
>>
>>>
>>> On Thu, Aug 27, 2009 at 10:00 AM, Sven Richter
>>> wrote:
>>> > I found this thread:
>>> >
>>> http://stackoverflow.com/questions/660260/django-admin-form-for-many-to-many-relationship
>>> > on Stackoverflow, but when i try the suggested TabularInline thing i
>>> get the
>>> > error:
>>> >
>>> >  has no ForeignKey to
>>> >> > 'politlog.entry.models.Entries'>
>>> >
>>>
>>> At least with Django 1.0.x, the admin interface does not support
>>> many-to-many relationships on inlines -- it will always return an
>>> error like the one you got above.  Indeed, the message is technically
>>> accurate, because m2m relationships get implemented as a separate
>>> table, so there is no direct relationship between the two.
>>> InlineModelAdmin works great for one-to-many but not for many-to-many.
>>>
>>> I'd also be interested in solutions to this, not having found anything
>>> in a bunch of Google searches.  The alternative I'm planning on is
>>> having to hand-code some views, forms, and templates that let me do
>>> the right thing -- not a huge amount of work, but having admin do it
>>> for us would be way cool.
>>>
>>> Craig
>>>
>>>
>>> > Greetings
>>> > Sven
>>>
>>> >>>
>>>
>>
>

--~--~-~--~~~---~--~~
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: Many-to-many column admin interface

2009-08-28 Thread patrickk

I could be mistaken ... but why not using a third model.

C(models.model):
   a = models.ForeignKey('A')
   b = models.ForeignKey('B')

when editing either A or B, you could use C as inlines.

regards,
patrick


On 28 Aug., 17:18, Sven Richter  wrote:
> But i wonder how this would help me further.
> In the End it doesnt matter for me on which model i define the M2M relation.
> But i need to access the M2M Table from both models, at least in the view or
> in the template if not in the admin interface.
>
> I am having a hard time finding out how to achieve that.
>
> Any Ideas?
>
> Greetings
> Sven
>
> On Fri, Aug 28, 2009 at 3:04 PM, Sven Richter wrote:
>
> > I've opened a bug/feature request at:
> >http://code.djangoproject.com/ticket/11795#comment:2
> > if someone is interested.
>
> > Greetings
> > Sven
>
> > On Fri, Aug 28, 2009 at 6:59 AM, Craig McClanahan wrote:
>
> >> On Thu, Aug 27, 2009 at 10:00 AM, Sven Richter
> >> wrote:
> >> > I found this thread:
>
> >>http://stackoverflow.com/questions/660260/django-admin-form-for-many-...
> >> > on Stackoverflow, but when i try the suggested TabularInline thing i get
> >> the
> >> > error:
>
> >> >  has no ForeignKey to
> >>  >> > 'politlog.entry.models.Entries'>
>
> >> At least with Django 1.0.x, the admin interface does not support
> >> many-to-many relationships on inlines -- it will always return an
> >> error like the one you got above.  Indeed, the message is technically
> >> accurate, because m2m relationships get implemented as a separate
> >> table, so there is no direct relationship between the two.
> >> InlineModelAdmin works great for one-to-many but not for many-to-many.
>
> >> I'd also be interested in solutions to this, not having found anything
> >> in a bunch of Google searches.  The alternative I'm planning on is
> >> having to hand-code some views, forms, and templates that let me do
> >> the right thing -- not a huge amount of work, but having admin do it
> >> for us would be way cool.
>
> >> Craig
>
> >> > Greetings
> >> > Sven
>
>
--~--~-~--~~~---~--~~
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: Many-to-many column admin interface

2009-08-28 Thread Sven Richter
I've opened a bug/feature request at:
http://code.djangoproject.com/ticket/11795#comment:2
if someone is interested.


Greetings
Sven

On Fri, Aug 28, 2009 at 6:59 AM, Craig McClanahan wrote:

>
> On Thu, Aug 27, 2009 at 10:00 AM, Sven Richter
> wrote:
> > I found this thread:
> >
> http://stackoverflow.com/questions/660260/django-admin-form-for-many-to-many-relationship
> > on Stackoverflow, but when i try the suggested TabularInline thing i get
> the
> > error:
> >
> >  has no ForeignKey to
>  > 'politlog.entry.models.Entries'>
> >
>
> At least with Django 1.0.x, the admin interface does not support
> many-to-many relationships on inlines -- it will always return an
> error like the one you got above.  Indeed, the message is technically
> accurate, because m2m relationships get implemented as a separate
> table, so there is no direct relationship between the two.
> InlineModelAdmin works great for one-to-many but not for many-to-many.
>
> I'd also be interested in solutions to this, not having found anything
> in a bunch of Google searches.  The alternative I'm planning on is
> having to hand-code some views, forms, and templates that let me do
> the right thing -- not a huge amount of work, but having admin do it
> for us would be way cool.
>
> Craig
>
>
> > Greetings
> > Sven
>
> >
>

--~--~-~--~~~---~--~~
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: Many-to-many column admin interface

2009-08-28 Thread Craig McClanahan

On Thu, Aug 27, 2009 at 10:00 AM, Sven Richter wrote:
> I found this thread:
> http://stackoverflow.com/questions/660260/django-admin-form-for-many-to-many-relationship
> on Stackoverflow, but when i try the suggested TabularInline thing i get the
> error:
>
>  has no ForeignKey to  'politlog.entry.models.Entries'>
>

At least with Django 1.0.x, the admin interface does not support
many-to-many relationships on inlines -- it will always return an
error like the one you got above.  Indeed, the message is technically
accurate, because m2m relationships get implemented as a separate
table, so there is no direct relationship between the two.
InlineModelAdmin works great for one-to-many but not for many-to-many.

I'd also be interested in solutions to this, not having found anything
in a bunch of Google searches.  The alternative I'm planning on is
having to hand-code some views, forms, and templates that let me do
the right thing -- not a huge amount of work, but having admin do it
for us would be way cool.

Craig


> Greetings
> Sven

--~--~-~--~~~---~--~~
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: Many-to-many column admin interface

2009-08-27 Thread Sven Richter
I found this thread:
http://stackoverflow.com/questions/660260/django-admin-form-for-many-to-many-relationship
on Stackoverflow, but when i try the suggested TabularInline thing i get the
error:

 has no ForeignKey to


Greetings
Sven



On Thu, Aug 27, 2009 at 5:03 PM, Thomas Guettler  wrote:

>
> Hi,
>
> I had the same question some time ago and found no answer,
> but maybe you try harder.
>
> Sven Richter schrieb:
> > Hi,
> >
> > i have a new problem with my many-to-many field.
> >
> > I have two models A and B.
> > A(models.model):
> >   b = models.ManyToManyField('app.B')
> >
> > Now when i edit A in the admin interface everything is ok, i can select
> all
> > B instances A belongs to.
> >
> > What i need now is to be able to do the same thing from B's admin
> interface.
> > When i edit B i want to select all instances of A B belongs to.
> >
> > Is there a way to achieve that?
>
> --
> Thomas Guettler, http://www.thomas-guettler.de/
> E-Mail : guettli (*)
> thomas-guettler + de
>
> >
>

--~--~-~--~~~---~--~~
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: Many-to-many column admin interface

2009-08-27 Thread Thomas Guettler

Hi,

I had the same question some time ago and found no answer,
but maybe you try harder.

Sven Richter schrieb:
> Hi,
> 
> i have a new problem with my many-to-many field.
> 
> I have two models A and B.
> A(models.model):
>   b = models.ManyToManyField('app.B')
> 
> Now when i edit A in the admin interface everything is ok, i can select all
> B instances A belongs to.
> 
> What i need now is to be able to do the same thing from B's admin interface.
> When i edit B i want to select all instances of A B belongs to.
> 
> Is there a way to achieve that?

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

--~--~-~--~~~---~--~~
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: Many-to-many column

2009-08-26 Thread Sven Richter
Thank you very much. I think i get the idea.


Greetings
Sven

On Tue, Aug 25, 2009 at 10:51 PM, Peter Bengtsson  wrote:

>
> I fear your only option is to write a recursive function which you
> feed with what you define to be "the end of the chain".
> You can collect all the entries in a mutable list. Some example,
> untested, code:
>
> def get_all_parents(list_, current):
>for entry in current.following_to.all():
>list_.append(entry)
>list_.extend(get_all_parents(list_, entry)
>return list_
>
> current = A
> parents = []
> get_all_parents(parents, current)
> print parents
>
> Excuse me if I didn't get it right but it should get you started.
>
> On Aug 25, 10:11 am, Sven Richter  wrote:
> > Hi,
> >
> > i implemented a many-to-many field in my model like:
> > class Entries(models.Model):
> >   following_to = models.ManyToManyField('self', blank=True, null=True)
> >
> > Now i can get all related Entries in a template with
> entry.following_to.all.
> > But i want to go deeper in relationships.
> >
> > Lets say i have 4 Entries A, B, C, D.
> > A is following_to to B and
> > B is following_to to C and
> > C is following_to to D.
> > A.following_to.all gives back B.
> >
> > But what i need is to follow until the end of the chain is reached.
> > I need something like:
> > A.following_to.give_all_related_entries which then returns:
> > B, C, D
> >
> > Do i have to write my own template tag for that or is it already
> implemented
> > in Django?
> > Or maybe there is a better approach to solve my issue?
> >
> > I couldnt find a similar question or answer in the docs.
> >
> > Greetings
> > Sven
> >
>

--~--~-~--~~~---~--~~
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: Many-to-many column

2009-08-25 Thread Peter Bengtsson

I fear your only option is to write a recursive function which you
feed with what you define to be "the end of the chain".
You can collect all the entries in a mutable list. Some example,
untested, code:

def get_all_parents(list_, current):
for entry in current.following_to.all():
list_.append(entry)
list_.extend(get_all_parents(list_, entry)
return list_

current = A
parents = []
get_all_parents(parents, current)
print parents

Excuse me if I didn't get it right but it should get you started.

On Aug 25, 10:11 am, Sven Richter  wrote:
> Hi,
>
> i implemented a many-to-many field in my model like:
> class Entries(models.Model):
>   following_to = models.ManyToManyField('self', blank=True, null=True)
>
> Now i can get all related Entries in a template with entry.following_to.all.
> But i want to go deeper in relationships.
>
> Lets say i have 4 Entries A, B, C, D.
> A is following_to to B and
> B is following_to to C and
> C is following_to to D.
> A.following_to.all gives back B.
>
> But what i need is to follow until the end of the chain is reached.
> I need something like:
> A.following_to.give_all_related_entries which then returns:
> B, C, D
>
> Do i have to write my own template tag for that or is it already implemented
> in Django?
> Or maybe there is a better approach to solve my issue?
>
> I couldnt find a similar question or answer in the docs.
>
> Greetings
> Sven
--~--~-~--~~~---~--~~
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: many to many model

2009-08-03 Thread Malcolm Tredinnick

On Mon, 2009-08-03 at 03:49 -0700, elminio wrote:
> Hi,
> tahnks for reply I added additional ManyToManyfield to one table and
> admin panel looks ok but in fact even using syncdb new intermediate
> table wasn't created.
> Is there anything else I should do ?

Syncdb does not incrementally update models like this. You will either
have to look at the output of "./manage.py sql" and then manually add
the necessary pieces, or use something like "./manage.py reset" to drop
and recreate the model's tables (which will throw away the existing
data), or use a tool like South to do the database migration.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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: many to many model

2009-08-03 Thread elminio

Hi,
tahnks for reply I added additional ManyToManyfield to one table and
admin panel looks ok but in fact even using syncdb new intermediate
table wasn't created.
Is there anything else I should do ?



--~--~-~--~~~---~--~~
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: many to many model

2009-08-03 Thread Malcolm Tredinnick

On Mon, 2009-08-03 at 02:24 -0700, elminio wrote:
> Hello,
> 
> My problem is that I have (for example), a model teacher - subject
> many to many. So that I made additional table named teacherSubject
> with both ids.

Instead of thinking about what database tables would be created, use
Django's ORM as a Python tool. You want a relationship between the
Teacher and Subject models, so use the ManyToManyField() to create one.
Django will take care of creating the intermediate table and doing joins
with it correctly in queries. Manually creating the intermediate table
is making things much harder on yourself.

At a minimum, even if you create the intermediate model yourself, you
will need to use the ManyToManyField() on either the Teacher or Student
models and use the "through" parameter to describe the intermediate
model. Otherwise Django cannot know that teacher and student are
directly related. It thinks they are second-level relations, which isn't
so easy to map in the admin interface.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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: Many to Many is empty when saving parent object

2009-03-17 Thread Brandon Taylor

Ah, gotcha, so my signal is attached to the wrong sender. I was
thinking I would have access to the categories during the Entry's save
operation due to the m2m relationship on the field, but obviously not.

I'll move the signal and see what happens.

Thank you,
Brandon

On Mar 16, 6:53 pm, Malcolm Tredinnick 
wrote:
> On Mon, 2009-03-16 at 08:48 -0700, Brandon Taylor wrote:
> > Hi everyone,
>
> > I'm running Python 2.6.1, Django Trunk.
>
> > I have a model (Entry) with a ManyToMany (Categories). I need to be
> > able to iterate over these categories whenever my parent model is
> > saved.
>
> > I've tried overriding save_model in the admin, and adding a post_save
> > signal to Entry in order to be able to iterate over the categories.
> > The problem only occurs on an insert. If I do:
>
> > class Entry(models.Model):
> >     name = models.CharField(max_length=100)
> >     categories = models.ManyToManyField(Category)
>
> >     class Meta:
> >         verbose_name_plural = 'Entries'
>
> >     def __unicode__(self):
> >         return self.name
>
> > class EntryAdmin(admin.ModelAdmin):
> >     def save_model(self, request, obj, form, change):
> >         obj.save()
> >         print obj.categories.all()
>
> > obj.categories.all() = []
>
> > However, when performing an update, I have a list of Category objects.
> > Is this a model lifecycle issue as far as when the ManyToMany gets
> > saved? What can I do to be able to access the list of categories when
> > the object is created?
>
> Many-to-many relations cannot be saved until the object itself is saved,
> since they need ot know the object's pk value to use in the relation
> table. Consequently, many-to-many handling in forms is done after saving
> the model itself. You're trying to look up the categories before they've
> been saved.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
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: Many to Many is empty when saving parent object

2009-03-16 Thread Malcolm Tredinnick

On Mon, 2009-03-16 at 08:48 -0700, Brandon Taylor wrote:
> Hi everyone,
> 
> I'm running Python 2.6.1, Django Trunk.
> 
> I have a model (Entry) with a ManyToMany (Categories). I need to be
> able to iterate over these categories whenever my parent model is
> saved.
> 
> I've tried overriding save_model in the admin, and adding a post_save
> signal to Entry in order to be able to iterate over the categories.
> The problem only occurs on an insert. If I do:
> 
> class Entry(models.Model):
> name = models.CharField(max_length=100)
> categories = models.ManyToManyField(Category)
> 
> class Meta:
> verbose_name_plural = 'Entries'
> 
> def __unicode__(self):
> return self.name
> 
> class EntryAdmin(admin.ModelAdmin):
> def save_model(self, request, obj, form, change):
> obj.save()
> print obj.categories.all()
> 
> obj.categories.all() = []
> 
> However, when performing an update, I have a list of Category objects.
> Is this a model lifecycle issue as far as when the ManyToMany gets
> saved? What can I do to be able to access the list of categories when
> the object is created?

Many-to-many relations cannot be saved until the object itself is saved,
since they need ot know the object's pk value to use in the relation
table. Consequently, many-to-many handling in forms is done after saving
the model itself. You're trying to look up the categories before they've
been saved.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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: Many to Many entries being duplicated, any ideas?

2008-12-09 Thread Darthmahon

I'll give it a go :) Thanks for your help Ben.

On Dec 9, 9:50 am, Ben Eliott <[EMAIL PROTECTED]> wrote:
> hmm, don't know. that's the documented approach. you might want to  
> investigate intermediary tables/models etc.
>
> On 9 Dec 2008, at 09:24, Darthmahon wrote:
>
>
>
> > Ahh yes possibly. Any downsides to using this?
>
> > On Dec 9, 9:19 am, Ben Eliott <[EMAIL PROTECTED]> wrote:
> >> Do you want something like this?
> >> friends_new = models.ManyToManyField("self",symmetrical=False)
>
> >> On 9 Dec 2008, at 09:06, Darthmahon wrote:
>
> >>> Hi Guys,
>
> >>> Just bumping this up as I still can't figure out why this is
> >>> happening :/
>
> >>> On Dec 8, 9:27 pm, Darthmahon <[EMAIL PROTECTED]> wrote:
>  Hi Guys,
>
>  I've got a model that has a Many to Many relationship on one of the
>  fields. This relationship is basically on itself though like this:
>
>  #
>
>  class UserProfile(models.Model):
>
>          user                    = models.ForeignKey(User,
>  unique=True)
>          friends_new     = models.ManyToManyField('UserProfile',
>  blank=True,
>  related_name='friend_set_new')
>
>  #
>
>  I'm trying to "add" to the friends_new field using this code:
>
>  #
>
>  # get users
>  initiator_profile = UserProfile.objects.get(user=request.user.id)
>  recipient_profile = UserProfile.objects.get(user=username)
>
>  # now add them as a friend
>  initiator_profile.friends_new.add(recipient_profile)
>
>  #
>
>  Now the problem I'm having is that it is adding the friendship to
>  BOTH
>  userprofiles, initiator and recipient. And when I try to remove the
>  relationship, again it removes BOTH. So in the database it has two
>  entries when I only expect there to be one.
>
>  Hope I've made that clear enough, any ideas how to get around this?
>
>  Cheers,
>  Chris
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many to Many entries being duplicated, any ideas?

2008-12-09 Thread Ben Eliott

hmm, don't know. that's the documented approach. you might want to  
investigate intermediary tables/models etc.


On 9 Dec 2008, at 09:24, Darthmahon wrote:

>
> Ahh yes possibly. Any downsides to using this?
>
> On Dec 9, 9:19 am, Ben Eliott <[EMAIL PROTECTED]> wrote:
>> Do you want something like this?
>> friends_new = models.ManyToManyField("self",symmetrical=False)
>>
>> On 9 Dec 2008, at 09:06, Darthmahon wrote:
>>
>>
>>
>>> Hi Guys,
>>
>>> Just bumping this up as I still can't figure out why this is
>>> happening :/
>>
>>> On Dec 8, 9:27 pm, Darthmahon <[EMAIL PROTECTED]> wrote:
 Hi Guys,
>>
 I've got a model that has a Many to Many relationship on one of the
 fields. This relationship is basically on itself though like this:
>>
 #
>>
 class UserProfile(models.Model):
>>
 user= models.ForeignKey(User,
 unique=True)
 friends_new = models.ManyToManyField('UserProfile',
 blank=True,
 related_name='friend_set_new')
>>
 #
>>
 I'm trying to "add" to the friends_new field using this code:
>>
 #
>>
 # get users
 initiator_profile = UserProfile.objects.get(user=request.user.id)
 recipient_profile = UserProfile.objects.get(user=username)
>>
 # now add them as a friend
 initiator_profile.friends_new.add(recipient_profile)
>>
 #
>>
 Now the problem I'm having is that it is adding the friendship to
 BOTH
 userprofiles, initiator and recipient. And when I try to remove the
 relationship, again it removes BOTH. So in the database it has two
 entries when I only expect there to be one.
>>
 Hope I've made that clear enough, any ideas how to get around this?
>>
 Cheers,
 Chris
> >


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many to Many entries being duplicated, any ideas?

2008-12-09 Thread Darthmahon

Ahh yes possibly. Any downsides to using this?

On Dec 9, 9:19 am, Ben Eliott <[EMAIL PROTECTED]> wrote:
> Do you want something like this?
> friends_new = models.ManyToManyField("self",symmetrical=False)
>
> On 9 Dec 2008, at 09:06, Darthmahon wrote:
>
>
>
> > Hi Guys,
>
> > Just bumping this up as I still can't figure out why this is
> > happening :/
>
> > On Dec 8, 9:27 pm, Darthmahon <[EMAIL PROTECTED]> wrote:
> >> Hi Guys,
>
> >> I've got a model that has a Many to Many relationship on one of the
> >> fields. This relationship is basically on itself though like this:
>
> >> #
>
> >> class UserProfile(models.Model):
>
> >>         user                    = models.ForeignKey(User,  
> >> unique=True)
> >>         friends_new     = models.ManyToManyField('UserProfile',  
> >> blank=True,
> >> related_name='friend_set_new')
>
> >> #
>
> >> I'm trying to "add" to the friends_new field using this code:
>
> >> #
>
> >> # get users
> >> initiator_profile = UserProfile.objects.get(user=request.user.id)
> >> recipient_profile = UserProfile.objects.get(user=username)
>
> >> # now add them as a friend
> >> initiator_profile.friends_new.add(recipient_profile)
>
> >> #
>
> >> Now the problem I'm having is that it is adding the friendship to  
> >> BOTH
> >> userprofiles, initiator and recipient. And when I try to remove the
> >> relationship, again it removes BOTH. So in the database it has two
> >> entries when I only expect there to be one.
>
> >> Hope I've made that clear enough, any ideas how to get around this?
>
> >> Cheers,
> >> Chris
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many to Many entries being duplicated, any ideas?

2008-12-09 Thread Ben Eliott

Do you want something like this?
friends_new = models.ManyToManyField("self",symmetrical=False)

On 9 Dec 2008, at 09:06, Darthmahon wrote:

>
> Hi Guys,
>
> Just bumping this up as I still can't figure out why this is
> happening :/
>
> On Dec 8, 9:27 pm, Darthmahon <[EMAIL PROTECTED]> wrote:
>> Hi Guys,
>>
>> I've got a model that has a Many to Many relationship on one of the
>> fields. This relationship is basically on itself though like this:
>>
>> #
>>
>> class UserProfile(models.Model):
>>
>> user= models.ForeignKey(User,  
>> unique=True)
>> friends_new = models.ManyToManyField('UserProfile',  
>> blank=True,
>> related_name='friend_set_new')
>>
>> #
>>
>> I'm trying to "add" to the friends_new field using this code:
>>
>> #
>>
>> # get users
>> initiator_profile = UserProfile.objects.get(user=request.user.id)
>> recipient_profile = UserProfile.objects.get(user=username)
>>
>> # now add them as a friend
>> initiator_profile.friends_new.add(recipient_profile)
>>
>> #
>>
>> Now the problem I'm having is that it is adding the friendship to  
>> BOTH
>> userprofiles, initiator and recipient. And when I try to remove the
>> relationship, again it removes BOTH. So in the database it has two
>> entries when I only expect there to be one.
>>
>> Hope I've made that clear enough, any ideas how to get around this?
>>
>> Cheers,
>> Chris
> >


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many to Many entries being duplicated, any ideas?

2008-12-09 Thread Darthmahon

Hi Guys,

Just bumping this up as I still can't figure out why this is
happening :/

On Dec 8, 9:27 pm, Darthmahon <[EMAIL PROTECTED]> wrote:
> Hi Guys,
>
> I've got a model that has a Many to Many relationship on one of the
> fields. This relationship is basically on itself though like this:
>
> #
>
> class UserProfile(models.Model):
>
>         user                    = models.ForeignKey(User, unique=True)
>         friends_new     = models.ManyToManyField('UserProfile', blank=True,
> related_name='friend_set_new')
>
> #
>
> I'm trying to "add" to the friends_new field using this code:
>
> #
>
> # get users
> initiator_profile = UserProfile.objects.get(user=request.user.id)
> recipient_profile = UserProfile.objects.get(user=username)
>
> # now add them as a friend
> initiator_profile.friends_new.add(recipient_profile)
>
> #
>
> Now the problem I'm having is that it is adding the friendship to BOTH
> userprofiles, initiator and recipient. And when I try to remove the
> relationship, again it removes BOTH. So in the database it has two
> entries when I only expect there to be one.
>
> Hope I've made that clear enough, any ideas how to get around this?
>
> Cheers,
> Chris
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many-to-Many to exists table

2008-12-03 Thread nucles

Thank you Thomas for your feedback!

We need a Many-To-Many Relation not to "group", but to
"user_auth_group".
I try to draw the desirable result:

user --- user_auth_group  group
   |
   |
 user_auth_group_area
   |
   |
area

Regards,
Dennis



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many-to-Many to exists table

2008-12-02 Thread Thomas Guettler

If I understood you problem:

{{{
from django.contrib.auth.models import Group
class Area(models.Model):
groups=models.ManyToManyField(Group)
}}}

This creates a Many-To-May relation to Group.

Copied from brain to keyboard (untested)

HTH,
  Thomas

nucles schrieb:
> Hello Django-People,
>
> we use the embedded functionality of the user authentication in
> Django.
> We use folowing models: "user", "auth_group", "auth_user_group" and
> other embedded models that does not matter in this context.
> We would like to add the additional entity "area" with M-to-M relation
> to the "user_auth_group" entity (please note: "user" has M-to-M
> relation to "auth_group")
>
> How can we do this? The "user_auth_group" will be automatically
> generate from Django, so we can not relate to this entity from any
> other model.
>
> We can of cause create our own user authentication without embedded
> user authentication in Django, but is this the best solution?
> I hope you understand our problem.
>
> Thank you.
> Regard
> Nucles
>
>
> >
>   


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: many to many matrix

2008-11-20 Thread Malcolm Tredinnick


On Thu, 2008-11-20 at 00:19 -0800, frans wrote:
> Hi, I was wondering if there is some way to create a "matrix display"
> for viewing/editing many to many relationships between objects ?
> 
> I've been thinking to use django for network documentation. My idea is
> to put all the networks we host or talk with in a matrix. Where you
> see all the networks on the left, and on the top.
> In the "cells" we could then define if traffic is allowed or not. And
> maybe the direction.
> 
> It should be possible with the django admin framework right ? 

Not easily. It would require a reasonable amount of customisation and if
you're not a programmer, would probably be quite difficult. Since there
could be dozens or hundreds of objects on each axis, which makes a table
that scrolls horizontally and vertically. You end up needing to develop
something equivalent to a spreadsheet display.

It would be possible to do something like this, since there are existing
Javascript widgets -- such as YUI's DataTable -- which allow that sort
of scrollable display. But it's not an out-of-the-box, flick-a-switch
option.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many to Many where two fields in one model are related

2008-09-30 Thread Steve Bergman

Thank you.  That looks to be exactly what I need.  I remember seeing
that on the ToDo list leading up to 1.0, but didn't realize how it
applied to my situation.

-Steve
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many to Many where two fields in one model are related

2008-09-30 Thread Rajesh Dhawan


> I'm working on an app for planning balanced daily diets.  And I'm
> having trouble figuring out how to set up my models.  I have:
>
> Ingredient(models.Model):
> ingredient_name = CharField(max_length=50)
> unit = CharField(max_length=15)
> calories = DecimalField(max_digits=6, decimal_places=2)
>
> Recipe(models.Model):
> recipe_name = CharField(max_length=50)
> ingredients = ManyToMany(Ingredient)
> amount = DecimalField(max_digits=6, decimal_places=2)
>
> An ingredient can be in many recipes and a recipe has many
> ingredients.  The thing is, in a Recipe I want to have an arbitrary
> number of ingredients, and I need for each ingredient to be associated
> with an amount. I could use multiple ForeignKey fields from in Recipe
> to Ingredient, and multiple amount fields in Recipe, but that seems
> klunky. Is there a "right" way to do this?

You can use the "through" attribute on your M2M definition. See:
http://docs.djangoproject.com/en/dev//topics/db/models/#extra-fields-on-many-to-many-relationships

That will allow you to add fields like amount to each M2M relation.

-RD
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many-to-Many different models (quasi-tagging)

2008-09-29 Thread Joshua Jonah
I never thought of that, i can just use the comments system, thanx for 
that Malcolm.

Malcolm Tredinnick wrote:
> On Mon, 2008-09-29 at 20:45 -0700, joshuajonah wrote:
>   
>> Also i should say, I'd like to be able to attach multiple "notes" to
>> any given model.
>> 
>
> Replace "note" with "comment" and it's basically the same setup. So have
> a look at how Django's comments app does this
> (django.contrib.comments.models). You won't need the abstract base class
> stuff in there, but the generic relation stuff is the clue you'll need.
>
> Regards,
> Malcolm
>
>
>
> >
>
>   


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many-to-Many different models (quasi-tagging)

2008-09-29 Thread Malcolm Tredinnick


On Mon, 2008-09-29 at 20:45 -0700, joshuajonah wrote:
> Also i should say, I'd like to be able to attach multiple "notes" to
> any given model.

Replace "note" with "comment" and it's basically the same setup. So have
a look at how Django's comments app does this
(django.contrib.comments.models). You won't need the abstract base class
stuff in there, but the generic relation stuff is the clue you'll need.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many-to-Many different models (quasi-tagging)

2008-09-29 Thread joshuajonah

Also i should say, I'd like to be able to attach multiple "notes" to
any given model.

On Sep 29, 11:42 pm, joshuajonah <[EMAIL PROTECTED]> wrote:
> Hi guys,
>
>     I'm making a little basic intranet CRM. Here's the models right
> now, pretty straight forward:
>
> class Person(models.Model):
>     url = models.SlugField(max_length=100)
>     first_name = models.CharField(max_length=100)
>     last_name = models.CharField(max_length=100)
>     business = models.ForeignKey('Business')
>     phone = models.CharField(max_length=100)
>     email = models.EmailField()
>     address = models.TextField()
>     date_added = models.DateField(auto_now_add=True)
>
> class Business(models.Model):
>     url = models.SlugField(max_length=100)
>     name = models.CharField(max_length=100)
>     phone = models.CharField(max_length=100)
>     email = models.EmailField()
>     address = models.TextField()
>     website = models.URLField()
>     date_added = models.DateField(auto_now_add=True)
>
> class Project(models.Model):
>     url = models.SlugField(max_length=100)
>     name = models.CharField(max_length=100)
>     description = models.TextField()
>     website = models.URLField()
>     client = models.ForeignKey('Business')
>     date_added = models.DateField(auto_now_add=True)
>
> class Milestone(models.Model):
>     project = models.ForeignKey('Project')
>     date_due = models.DateField()
>     description = models.TextField()
>     date_added = models.DateField(auto_now_add=True)
>
> Now, I need to make a models called 'Note'. I would like to be able to
> attach a 'note' to a 'Project' or a 'Person' or anything for that
> matter, basically tagging, only with a textfield.
>
> Is there any easy way of accomplishing this without breaking it down
> to 'PersonNote', 'ProjectNote', etc...?
>
> Thanx in advance.
> Joshua
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many-To-Many with extra fields

2008-09-23 Thread akonsu

this is untested:

m = Membership.objects.select_related().get(person__name='ringo')
ringo = m.person

i agree, this is not as convenient as could be. may be it will be in
the next version?

konstantin

On Sep 23, 5:16 pm, Nate Thelen <[EMAIL PROTECTED]> wrote:
> Yeah, that would work, too.  I was thinking more like if you got the
> ringo like this:
>
> ringo = Person.objects.select_related(depth=2).get(name='ringo')
>
> how could you get the data without having to make another DB call.
>
> Ideas?
>
> Thanks,
> Nate
>
> On Sep 23, 2:04 pm, akonsu <[EMAIL PROTECTED]> wrote:
>
> > hello,
>
> > how about
>
> > for m in Membership.objects.filter(person=ringo) : print m.date_joined
>
> > konstantin
>
> > On Sep 23, 4:58 pm, Nate Thelen <[EMAIL PROTECTED]> wrote:
>
> > > So if I have a Person object "ringo" and I want to get info about the
> > > Groups he is a member of, I would do this:
>
> > > for group in ringo.group_set.all()
> > >     print( group.name )
>
> > > My question is, how do I print the "date_joined" without having to do
> > > this:
>
> > > for group in ringo.group_set.all()
> > >     print( Membership.objects.get(person=ringo,
> > > group=group).date_joined )
>
> > > That seems very DB inefficient.
>
> > > Nate
>
> > > On Sep 19, 9:43 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
> > > wrote:
>
> > > > On Sat, Sep 20, 2008 at 8:37 AM, Nate Thelen <[EMAIL PROTECTED]> wrote:
>
> > > > > Looking at the docs here:
>
> > > > >http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o...
>
> > > > > I cannot find any reference to how to access the data in the
> > > > > "Membership" table.  For example, if I have a reference to the
> > > > > "beatles" object, how do I find the "date_joined" for each of the
> > > > > "Person" objects.  I have looked through the other sections of the
> > > > > documentation, searched this group, and searched via Google, but
> > > > > couldn't find the info.
>
> > > > Short version: You access the membership table using the foreign key
> > > > relationship that the membership defines.
>
> > > > Long version: Your question ("the date_joined for each person object")
> > > > is actually ill posed - a person doesn't have a date_joined without a
> > > > group to also give context. "The date person X joined group Y" can be
> > > > answered as:
>
> > > > >>> Membership.objects.get(person=X, group=y).date_joined
>
> > > > It might help to think about it like this - m2m-intermediate tables
> > > > don't add extra data to an m2m relation, they make a 2-step foreign
> > > > key relation behave like an m2m relation.
>
> > > > Yours,
> > > > Russ Magee %-)
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many-To-Many with extra fields

2008-09-23 Thread Nate Thelen

Yeah, that would work, too.  I was thinking more like if you got the
ringo like this:

ringo = Person.objects.select_related(depth=2).get(name='ringo')

how could you get the data without having to make another DB call.

Ideas?

Thanks,
Nate

On Sep 23, 2:04 pm, akonsu <[EMAIL PROTECTED]> wrote:
> hello,
>
> how about
>
> for m in Membership.objects.filter(person=ringo) : print m.date_joined
>
> konstantin
>
> On Sep 23, 4:58 pm, Nate Thelen <[EMAIL PROTECTED]> wrote:
>
> > So if I have a Person object "ringo" and I want to get info about the
> > Groups he is a member of, I would do this:
>
> > for group in ringo.group_set.all()
> >     print( group.name )
>
> > My question is, how do I print the "date_joined" without having to do
> > this:
>
> > for group in ringo.group_set.all()
> >     print( Membership.objects.get(person=ringo,
> > group=group).date_joined )
>
> > That seems very DB inefficient.
>
> > Nate
>
> > On Sep 19, 9:43 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
> > wrote:
>
> > > On Sat, Sep 20, 2008 at 8:37 AM, Nate Thelen <[EMAIL PROTECTED]> wrote:
>
> > > > Looking at the docs here:
>
> > > >http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o...
>
> > > > I cannot find any reference to how to access the data in the
> > > > "Membership" table.  For example, if I have a reference to the
> > > > "beatles" object, how do I find the "date_joined" for each of the
> > > > "Person" objects.  I have looked through the other sections of the
> > > > documentation, searched this group, and searched via Google, but
> > > > couldn't find the info.
>
> > > Short version: You access the membership table using the foreign key
> > > relationship that the membership defines.
>
> > > Long version: Your question ("the date_joined for each person object")
> > > is actually ill posed - a person doesn't have a date_joined without a
> > > group to also give context. "The date person X joined group Y" can be
> > > answered as:
>
> > > >>> Membership.objects.get(person=X, group=y).date_joined
>
> > > It might help to think about it like this - m2m-intermediate tables
> > > don't add extra data to an m2m relation, they make a 2-step foreign
> > > key relation behave like an m2m relation.
>
> > > Yours,
> > > Russ Magee %-)
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many-To-Many with extra fields

2008-09-23 Thread akonsu

hello,

how about

for m in Membership.objects.filter(person=ringo) : print m.date_joined

konstantin

On Sep 23, 4:58 pm, Nate Thelen <[EMAIL PROTECTED]> wrote:
> So if I have a Person object "ringo" and I want to get info about the
> Groups he is a member of, I would do this:
>
> for group in ringo.group_set.all()
>     print( group.name )
>
> My question is, how do I print the "date_joined" without having to do
> this:
>
> for group in ringo.group_set.all()
>     print( Membership.objects.get(person=ringo,
> group=group).date_joined )
>
> That seems very DB inefficient.
>
> Nate
>
> On Sep 19, 9:43 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
> wrote:
>
> > On Sat, Sep 20, 2008 at 8:37 AM, Nate Thelen <[EMAIL PROTECTED]> wrote:
>
> > > Looking at the docs here:
>
> > >http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o...
>
> > > I cannot find any reference to how to access the data in the
> > > "Membership" table.  For example, if I have a reference to the
> > > "beatles" object, how do I find the "date_joined" for each of the
> > > "Person" objects.  I have looked through the other sections of the
> > > documentation, searched this group, and searched via Google, but
> > > couldn't find the info.
>
> > Short version: You access the membership table using the foreign key
> > relationship that the membership defines.
>
> > Long version: Your question ("the date_joined for each person object")
> > is actually ill posed - a person doesn't have a date_joined without a
> > group to also give context. "The date person X joined group Y" can be
> > answered as:
>
> > >>> Membership.objects.get(person=X, group=y).date_joined
>
> > It might help to think about it like this - m2m-intermediate tables
> > don't add extra data to an m2m relation, they make a 2-step foreign
> > key relation behave like an m2m relation.
>
> > Yours,
> > Russ Magee %-)
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many-To-Many with extra fields

2008-09-23 Thread Nate Thelen

So if I have a Person object "ringo" and I want to get info about the
Groups he is a member of, I would do this:

for group in ringo.group_set.all()
print( group.name )

My question is, how do I print the "date_joined" without having to do
this:

for group in ringo.group_set.all()
print( Membership.objects.get(person=ringo,
group=group).date_joined )

That seems very DB inefficient.

Nate


On Sep 19, 9:43 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On Sat, Sep 20, 2008 at 8:37 AM, Nate Thelen <[EMAIL PROTECTED]> wrote:
>
> > Looking at the docs here:
>
> >http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o...
>
> > I cannot find any reference to how to access the data in the
> > "Membership" table.  For example, if I have a reference to the
> > "beatles" object, how do I find the "date_joined" for each of the
> > "Person" objects.  I have looked through the other sections of the
> > documentation, searched this group, and searched via Google, but
> > couldn't find the info.
>
> Short version: You access the membership table using the foreign key
> relationship that the membership defines.
>
> Long version: Your question ("the date_joined for each person object")
> is actually ill posed - a person doesn't have a date_joined without a
> group to also give context. "The date person X joined group Y" can be
> answered as:
>
> >>> Membership.objects.get(person=X, group=y).date_joined
>
> It might help to think about it like this - m2m-intermediate tables
> don't add extra data to an m2m relation, they make a 2-step foreign
> key relation behave like an m2m relation.
>
> Yours,
> Russ Magee %-)
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many-To-Many with extra fields

2008-09-19 Thread Russell Keith-Magee

On Sat, Sep 20, 2008 at 8:37 AM, Nate Thelen <[EMAIL PROTECTED]> wrote:
>
> Looking at the docs here:
>
> http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships
>
> I cannot find any reference to how to access the data in the
> "Membership" table.  For example, if I have a reference to the
> "beatles" object, how do I find the "date_joined" for each of the
> "Person" objects.  I have looked through the other sections of the
> documentation, searched this group, and searched via Google, but
> couldn't find the info.

Short version: You access the membership table using the foreign key
relationship that the membership defines.

Long version: Your question ("the date_joined for each person object")
is actually ill posed - a person doesn't have a date_joined without a
group to also give context. "The date person X joined group Y" can be
answered as:

>>> Membership.objects.get(person=X, group=y).date_joined

It might help to think about it like this - m2m-intermediate tables
don't add extra data to an m2m relation, they make a 2-step foreign
key relation behave like an m2m relation.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many-To-Many with extra fields

2008-09-19 Thread Rock

In my code I have a reference and a name such that I can do perform a
"get" to procure the reference to the correct intermediate object.
Then I simply interrogate that object directly. It should be possible
to do a "values" style query instead if you only want a particular
field or set of fields.

Hope that helps!


On Sep 19, 7:37 pm, Nate Thelen <[EMAIL PROTECTED]> wrote:
> Looking at the docs here:
>
> http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-o...
>
> I cannot find any reference to how to access the data in the
> "Membership" table.  For example, if I have a reference to the
> "beatles" object, how do I find the "date_joined" for each of the
> "Person" objects.  I have looked through the other sections of the
> documentation, searched this group, and searched via Google, but
> couldn't find the info.
>
> Thanks,
> Nate
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many to Many field Assignment

2008-08-31 Thread Vadivel Kumar
i see that there exists a handy way -- *icontains* does exactly what iam
looking at

On Sun, Aug 31, 2008 at 9:35 PM, Vadivel Kumar <[EMAIL PROTECTED]> wrote:

>  Thanks Michael,
>
> I solved the problem - i had a silly mistake in the way how i handled  to
> check the existing tag. But, now the problem is when i check the given tag
> text against the database, i do it as like below,
>
>newTag = request.POST['tag']
>existingTag = Tags.objects.filter(TagName__exact=newTag)
>
> Now, I wanted to check it more perfectly, I want to check with
> case-insensitve etc., I am not seeing any appropriate django method to do
> this, may be i should check the documentation.
>
> Thanks for your quick help.
>

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many to Many field Assignment

2008-08-31 Thread Vadivel Kumar
Thanks Michael,

I solved the problem - i had a silly mistake in the way how i handled  to
check the existing tag. But, now the problem is when i check the given tag
text against the database, i do it as like below,

   newTag = request.POST['tag']
   existingTag = Tags.objects.filter(TagName__exact=newTag)

Now, I wanted to check it more perfectly, I want to check with
case-insensitve etc., I am not seeing any appropriate django method to do
this, may be i should check the documentation.

Thanks for your quick help.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many to Many field Assignment

2008-08-31 Thread Michael Newman

On Aug 31, 11:14 am, "Vadivel Kumar" <[EMAIL PROTECTED]> wrote:
> I know this might sound very newbie .. its true
>
> How can i assign an exising record of the child table to an parent record.
> For example I have two models,
>
>     class User (models.Model):
>          ... all other fields ...
>         Tags  = models.ManyToManyField(Tag)
>
>      class Tag (models.Mode):
>          .. all fields ..
>
> The problem i am facing is whenever i create a new user and add an existing
> tag object to User.Tags.add() method it creates a new record in Tag table
> instead i need to just map the record with the new user.
>
> I know am missing a paramount thing .. what is that ?

The methods you are using, if I understand you correctly, should work.
I would need to take a look at the exact code that is creating a new
object to help you out. But one thing you can look at is
http://www.djangoproject.com/documentation/models/many_to_many/  . It
is very helpful at showing how the manytomanyfields work. If you are
still having an issue, post the offending code to dpaste.com and we
can take a look.

Thanks,
Michael
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Many to many array accessible from template?

2008-07-16 Thread Jashugan

On Jul 13, 6:10 am, Darthmahon <[EMAIL PROTECTED]> wrote:
> Alex,
>
> I don't understand what you mean by that? message.users.all prints out
> a list of users based on the many to many. I just want to check if the
> current user is in message.users.all - are you saying I can't because
> I am passing in a string, not an actual UserProfile instance?
>

You are probably not passing in a UserProfile. Have you tried using a
"raise Exception(value)" right after the signature of your filter to
see what you are getting?

@register.filter
def IN(value,arg):
raise Exception("Type of value: %s, Type of arg: %s" %
(type(value), type(arg)))
return value in arg

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



  1   2   3   >