Re: I'm missing something with Models and database migrations

2015-12-22 Thread Michael Molloy
I figured it out, again with help from Vijay. Thanks for getting me 
thinking in the right direction.

So here is my cross reference model:

class Invoice_Line_Items(models.Model):
 created_dt = models.DateField('created date', auto_now=True)
 invoice = models.ManyToManyField(Invoices)
 line_item = models.ManyToManyField(Line_Items)



I was incorrectly looking for a single table named Invoice_Line_Items because I 
didn't understand how Django creates multiple tables to deal with ManyToMany 
relationships like this. The table I was expecting was there, but it didn't 
have columns for invoice IDs or line_item IDs. Django actually created these 
three tables to handle this:


gpga_invoice_line_items

gpga_invoice_line_items_invoice

gpga_invoice_line_items_line_item  


Thanks again.

--M




On Tuesday, December 22, 2015 at 8:49:10 PM UTC-6, Michael Molloy wrote:
>
> Still confused. I think I still need to create the cross reference Django 
> model myself, and then use makemigrations to turn it into a table.
>
> I need a place to store invoices and associated line items, so if the 
> model code I put in my first post is incorrect, what should it look like? 
>
> --Michael
>
> On Tuesday, December 22, 2015 at 8:29:36 PM UTC-6, Michael Molloy wrote:
>>
>> I was trying to create the cross reference table myself. I'm coming at 
>> this from a java/oracle background where I would create two tables 
>> (invoices and line_items), and then a third (invoice_line_item_xref) that 
>> would contain invoice IDs and associated line item IDs. I think you just 
>> helped me see my misunderstanding of how Django does things.
>>
>> So, in the list of tables (now that I know what I'm looking for), I see a 
>> table called invoice_line_items_xref_invoice_id and another called 
>> invoice_line_items_xref_line_item_id. Those must be the two tables that 
>> Django created to handle the many to many relationship. Is that correct? 
>>
>> --Michael 
>>
>> On Tuesday, December 22, 2015 at 6:29:51 PM UTC-6, Vijay Khemlani wrote:
>>>
>>> You have two pairs of fields with the same name (line_item_id 
>>> and invoice_id), what are you trying to do exactly? Why the IntegerFields?
>>>
>>> In a Many To Many relation the columns are added to a third table 
>>> between the models.
>>>
>>> On Tue, Dec 22, 2015 at 9:20 PM, Michael Molloy  
>>> wrote:
>>>
 Python 3.3 and Django 1.8 running on Openshift with a Postgresql 
 database

 I'm trying to set up an Invoices table, a Line_Item table, and a cross 
 reference between them. Here are the relevant models:


 class Invoices(models.Model):
  invoice_date = models.DateField('created date', auto_now=True)

 class Line_Items(models.Model):
  descr = models.CharField(max_length=100)
  cost = models.DecimalField(max_digits=5, decimal_places=2)

 class Invoice_Line_Items_Xref(models.Model):
  created_dt = models.DateField(auto_now=True)
  invoice_id = models.IntegerField(default=0)
  line_item_id = models.IntegerField(default=0)
  invoice_id = models.ManyToManyField(Invoices)
  line_item_id = models.ManyToManyField(Line_Items)




 I don't think the syntax for the cross reference table above is correct, 
 but it is one of the permutations that I've tried. The layout above 
 resulted in this migration after running makemigrations


 operations = [
  migrations.AddField(
  model_name='invoice_line_items_xref',
  name='invoice_id',
  field=models.ManyToManyField(to='gpga.Invoices'),
  ),
  migrations.AddField(
  model_name='invoice_line_items_xref',
  name='line_item_id',
  field=models.ManyToManyField(to='gpga.Line_Items'),
  ),
 ]



 However, when I push the code to Openshift, even though the migration runs 
 against the database, the invoice_id and line_item_id columns do not 
 appear on the database table. 


 I have no idea what I'm doing wrong. Thank you for any help.


 --Michael

 -- 
 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/9953458c-908d-4376-89f9-eb68e37d527a%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 

Re: I'm missing something with Models and database migrations

2015-12-22 Thread Michael Molloy
Still confused. I think I still need to create the cross reference Django 
model myself, and then use makemigrations to turn it into a table.

I need a place to store invoices and associated line items, so if the model 
code I put in my first post is incorrect, what should it look like? 

--Michael

On Tuesday, December 22, 2015 at 8:29:36 PM UTC-6, Michael Molloy wrote:
>
> I was trying to create the cross reference table myself. I'm coming at 
> this from a java/oracle background where I would create two tables 
> (invoices and line_items), and then a third (invoice_line_item_xref) that 
> would contain invoice IDs and associated line item IDs. I think you just 
> helped me see my misunderstanding of how Django does things.
>
> So, in the list of tables (now that I know what I'm looking for), I see a 
> table called invoice_line_items_xref_invoice_id and another called 
> invoice_line_items_xref_line_item_id. Those must be the two tables that 
> Django created to handle the many to many relationship. Is that correct? 
>
> --Michael 
>
> On Tuesday, December 22, 2015 at 6:29:51 PM UTC-6, Vijay Khemlani wrote:
>>
>> You have two pairs of fields with the same name (line_item_id 
>> and invoice_id), what are you trying to do exactly? Why the IntegerFields?
>>
>> In a Many To Many relation the columns are added to a third table between 
>> the models.
>>
>> On Tue, Dec 22, 2015 at 9:20 PM, Michael Molloy  
>> wrote:
>>
>>> Python 3.3 and Django 1.8 running on Openshift with a Postgresql database
>>>
>>> I'm trying to set up an Invoices table, a Line_Item table, and a cross 
>>> reference between them. Here are the relevant models:
>>>
>>>
>>> class Invoices(models.Model):
>>>  invoice_date = models.DateField('created date', auto_now=True)
>>>
>>> class Line_Items(models.Model):
>>>  descr = models.CharField(max_length=100)
>>>  cost = models.DecimalField(max_digits=5, decimal_places=2)
>>>
>>> class Invoice_Line_Items_Xref(models.Model):
>>>  created_dt = models.DateField(auto_now=True)
>>>  invoice_id = models.IntegerField(default=0)
>>>  line_item_id = models.IntegerField(default=0)
>>>  invoice_id = models.ManyToManyField(Invoices)
>>>  line_item_id = models.ManyToManyField(Line_Items)
>>>
>>>
>>>
>>>
>>> I don't think the syntax for the cross reference table above is correct, 
>>> but it is one of the permutations that I've tried. The layout above 
>>> resulted in this migration after running makemigrations
>>>
>>>
>>> operations = [
>>>  migrations.AddField(
>>>  model_name='invoice_line_items_xref',
>>>  name='invoice_id',
>>>  field=models.ManyToManyField(to='gpga.Invoices'),
>>>  ),
>>>  migrations.AddField(
>>>  model_name='invoice_line_items_xref',
>>>  name='line_item_id',
>>>  field=models.ManyToManyField(to='gpga.Line_Items'),
>>>  ),
>>> ]
>>>
>>>
>>>
>>> However, when I push the code to Openshift, even though the migration runs 
>>> against the database, the invoice_id and line_item_id columns do not appear 
>>> on the database table. 
>>>
>>>
>>> I have no idea what I'm doing wrong. Thank you for any help.
>>>
>>>
>>> --Michael
>>>
>>> -- 
>>> 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/9953458c-908d-4376-89f9-eb68e37d527a%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/0586e0cf-36c9-4011-bdad-316db5a16a09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: I'm missing something with Models and database migrations

2015-12-22 Thread Michael Molloy
I was trying to create the cross reference table myself. I'm coming at this 
from a java/oracle background where I would create two tables (invoices and 
line_items), and then a third (invoice_line_item_xref) that would contain 
invoice IDs and associated line item IDs. I think you just helped me see my 
misunderstanding of how Django does things.

So, in the list of tables (now that I know what I'm looking for), I see a 
table called invoice_line_items_xref_invoice_id and another called 
invoice_line_items_xref_line_item_id. Those must be the two tables that 
Django created to handle the many to many relationship. Is that correct? 

--Michael 

On Tuesday, December 22, 2015 at 6:29:51 PM UTC-6, Vijay Khemlani wrote:
>
> You have two pairs of fields with the same name (line_item_id 
> and invoice_id), what are you trying to do exactly? Why the IntegerFields?
>
> In a Many To Many relation the columns are added to a third table between 
> the models.
>
> On Tue, Dec 22, 2015 at 9:20 PM, Michael Molloy  > wrote:
>
>> Python 3.3 and Django 1.8 running on Openshift with a Postgresql database
>>
>> I'm trying to set up an Invoices table, a Line_Item table, and a cross 
>> reference between them. Here are the relevant models:
>>
>>
>> class Invoices(models.Model):
>>  invoice_date = models.DateField('created date', auto_now=True)
>>
>> class Line_Items(models.Model):
>>  descr = models.CharField(max_length=100)
>>  cost = models.DecimalField(max_digits=5, decimal_places=2)
>>
>> class Invoice_Line_Items_Xref(models.Model):
>>  created_dt = models.DateField(auto_now=True)
>>  invoice_id = models.IntegerField(default=0)
>>  line_item_id = models.IntegerField(default=0)
>>  invoice_id = models.ManyToManyField(Invoices)
>>  line_item_id = models.ManyToManyField(Line_Items)
>>
>>
>>
>>
>> I don't think the syntax for the cross reference table above is correct, but 
>> it is one of the permutations that I've tried. The layout above resulted in 
>> this migration after running makemigrations
>>
>>
>> operations = [
>>  migrations.AddField(
>>  model_name='invoice_line_items_xref',
>>  name='invoice_id',
>>  field=models.ManyToManyField(to='gpga.Invoices'),
>>  ),
>>  migrations.AddField(
>>  model_name='invoice_line_items_xref',
>>  name='line_item_id',
>>  field=models.ManyToManyField(to='gpga.Line_Items'),
>>  ),
>> ]
>>
>>
>>
>> However, when I push the code to Openshift, even though the migration runs 
>> against the database, the invoice_id and line_item_id columns do not appear 
>> on the database table. 
>>
>>
>> I have no idea what I'm doing wrong. Thank you for any help.
>>
>>
>> --Michael
>>
>> -- 
>> 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/9953458c-908d-4376-89f9-eb68e37d527a%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/8c97e56a-a196-4b73-84cd-76987ba41bf8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Migrate django project to eclipse/pydev ide

2015-12-22 Thread Clifford Ilkay

On 22/12/15 07:05 PM, Andrew Farrell wrote:

Could you also tell us:
1) Why you need to switch to Eclipse specifically rather than PyCharm 
, SublimeText 
, or (the one I use) Atom 
?


Andrew, there are things Eclipse does that those three editors don't do. 
For example, the Mylyn plugin and how it integrates Eclipse with Trac is 
unparalleled. I also find debugging with Eclipse to be quite good for 
the odd time that I need to step through code as opposed to prototyping 
in iPython.


Gary, move your existing project to some directory outside of wherever 
your default workspace is and create a new Django PyDev project with the 
same name as your existing project. Look inside the directory that got 
created and you'll see a couple of hidden files, .project and 
.pydevproject. Move those somewhere safe, delete the new project 
directory, move the existing project directory to the default workspace, 
and move the hidden files to the project directory.


You can also import an existing project.

As for virtualenv or venv, all you have to do is go to the project 
properties, select "PyDev - Interpreter/Grammar", "Click here to 
configure an interpreter not listed." and add the Python binary for your 
venv.


--
Regards,

Clifford Ilkay

+1 647-778-8696

--
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/5679F095.70103%40dinamis.com.
For more options, visit https://groups.google.com/d/optout.


Re: I'm missing something with Models and database migrations

2015-12-22 Thread Vijay Khemlani
You have two pairs of fields with the same name (line_item_id
and invoice_id), what are you trying to do exactly? Why the IntegerFields?

In a Many To Many relation the columns are added to a third table between
the models.

On Tue, Dec 22, 2015 at 9:20 PM, Michael Molloy  wrote:

> Python 3.3 and Django 1.8 running on Openshift with a Postgresql database
>
> I'm trying to set up an Invoices table, a Line_Item table, and a cross
> reference between them. Here are the relevant models:
>
>
> class Invoices(models.Model):
>  invoice_date = models.DateField('created date', auto_now=True)
>
> class Line_Items(models.Model):
>  descr = models.CharField(max_length=100)
>  cost = models.DecimalField(max_digits=5, decimal_places=2)
>
> class Invoice_Line_Items_Xref(models.Model):
>  created_dt = models.DateField(auto_now=True)
>  invoice_id = models.IntegerField(default=0)
>  line_item_id = models.IntegerField(default=0)
>  invoice_id = models.ManyToManyField(Invoices)
>  line_item_id = models.ManyToManyField(Line_Items)
>
>
>
>
> I don't think the syntax for the cross reference table above is correct, but 
> it is one of the permutations that I've tried. The layout above resulted in 
> this migration after running makemigrations
>
>
> operations = [
>  migrations.AddField(
>  model_name='invoice_line_items_xref',
>  name='invoice_id',
>  field=models.ManyToManyField(to='gpga.Invoices'),
>  ),
>  migrations.AddField(
>  model_name='invoice_line_items_xref',
>  name='line_item_id',
>  field=models.ManyToManyField(to='gpga.Line_Items'),
>  ),
> ]
>
>
>
> However, when I push the code to Openshift, even though the migration runs 
> against the database, the invoice_id and line_item_id columns do not appear 
> on the database table.
>
>
> I have no idea what I'm doing wrong. Thank you for any help.
>
>
> --Michael
>
> --
> 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/9953458c-908d-4376-89f9-eb68e37d527a%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/CALn3ei19SGbsdnmwgacUu_zqpf9hudYwJYPG9YzEofNPmzvouQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Persistent DB connections and WSGI

2015-12-22 Thread Jordi

Hi,

Can I take for granted that connections between the DB and Django get 
closed when threads get killed?
I take my max_connections in postgres to be the amount of WSGI threads + 
some safety margin, and put use Django
in persistent DB connection mode (CONN_MAX_AGE = None) to avoid the 
overhead of re-establishing connections, but then if for some
reason threads get killed abrubtly by WSGI and restarted, I may run out 
of max_connections if they didn't get closed properly?

Or is this not a concern?

Thanks
Jordi

--
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/5679D6CB.50200%40promani.be.
For more options, visit https://groups.google.com/d/optout.


I'm missing something with Models and database migrations

2015-12-22 Thread Michael Molloy
Python 3.3 and Django 1.8 running on Openshift with a Postgresql database

I'm trying to set up an Invoices table, a Line_Item table, and a cross 
reference between them. Here are the relevant models:


class Invoices(models.Model):
 invoice_date = models.DateField('created date', auto_now=True)

class Line_Items(models.Model):
 descr = models.CharField(max_length=100)
 cost = models.DecimalField(max_digits=5, decimal_places=2)

class Invoice_Line_Items_Xref(models.Model):
 created_dt = models.DateField(auto_now=True)
 invoice_id = models.IntegerField(default=0)
 line_item_id = models.IntegerField(default=0)
 invoice_id = models.ManyToManyField(Invoices)
 line_item_id = models.ManyToManyField(Line_Items)




I don't think the syntax for the cross reference table above is correct, but it 
is one of the permutations that I've tried. The layout above resulted in this 
migration after running makemigrations


operations = [
 migrations.AddField(
 model_name='invoice_line_items_xref',
 name='invoice_id',
 field=models.ManyToManyField(to='gpga.Invoices'),
 ),
 migrations.AddField(
 model_name='invoice_line_items_xref',
 name='line_item_id',
 field=models.ManyToManyField(to='gpga.Line_Items'),
 ),
]



However, when I push the code to Openshift, even though the migration runs 
against the database, the invoice_id and line_item_id columns do not appear on 
the database table. 


I have no idea what I'm doing wrong. Thank you for any help.


--Michael

-- 
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/9953458c-908d-4376-89f9-eb68e37d527a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Migrate django project to eclipse/pydev ide

2015-12-22 Thread Andrew Farrell
Could you also tell us:
1) Why you need to switch to Eclipse specifically rather than PyCharm
, SublimeText
, or (the one I use) Atom
?
2) What error Eclipse is showing or what functionality is not working?

On Tue, Dec 22, 2015 at 5:32 PM, Gary Roach 
wrote:

> Hi all;
>
> I have been working on a project for some time using Ninja-IDE.
> Unfortunately the development on Ninja has - for all practical purposes -
> stopped. It no longer works for me. I need to switch to Eclipse with the
> Pydev plugin and am having trouble finding out how to do this. I have
> looked at several howto's. So far I can follow them up to a point and then
> what shows up on the screen starts to depart from what's in the howto. The
> end result is that I can't finish the process. Also there is no mention of
> virtual environments. This worries me. I have multiple projects on my
> system.
>
> I'm using:
> Debian stretch Linux
> Eclipse 3.8
> pyDev 4.4.0
> django 1.8,4
> python 3.4
> venv (not virtualenv) virtual environment
> git with github repository
> postgresql 9.4 dbms
>
> Can someone point me in the right direction with this.
>
> Gary R.
>
> --
> 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/5679DD71.708%40verizon.net.
> 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/CA%2By5TLb_ogeU-aV2OLfOENxJGxG0WkUdX0H_0eh--9kmARnb6Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Migrate django project to eclipse/pydev ide

2015-12-22 Thread Gary Roach

Hi all;

I have been working on a project for some time using Ninja-IDE. 
Unfortunately the development on Ninja has - for all practical purposes 
- stopped. It no longer works for me. I need to switch to Eclipse with 
the Pydev plugin and am having trouble finding out how to do this. I 
have looked at several howto's. So far I can follow them up to a point 
and then what shows up on the screen starts to depart from what's in the 
howto. The end result is that I can't finish the process. Also there is 
no mention of virtual environments. This worries me. I have multiple 
projects on my system.


I'm using:
Debian stretch Linux
Eclipse 3.8
pyDev 4.4.0
django 1.8,4
python 3.4
venv (not virtualenv) virtual environment
git with github repository
postgresql 9.4 dbms

Can someone point me in the right direction with this.

Gary R.

--
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/5679DD71.708%40verizon.net.
For more options, visit https://groups.google.com/d/optout.


makemigrations of model with single table inheritance and child fields

2015-12-22 Thread Axel Rau
Hi all,

My db, which is in production (with none-Django software) has some (legacy) 
tables, which share a set of common fields and some fields, which differ by 
child. The attached single table model hierarchy worked for me, even if it’s 
not a legal Django arrangement. The ’type’ field is responsible to select the 
right child.

Now, I’m starting with migrations and see that makemigrations tries to create 
one mailbox table per child (because I have db_table there, which was needed to 
get the arrangement working).

Questions:

Is the above arrangement the best current praxis for the given legacy situation?
Can I stop makemigrations from looking at this model hierarchy at all and 
instead create a migration for some fake model?
Or asked differently, must I live with the situation where I maintain all my 
migrations by hand?

Splitting the models from the legacy tables in 2 apps comes into mind.

Any help appreciated,
Axel

-- 
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/F016760C-A041-41A5-9494-BDBBE165E317%40Chaos1.DE.
For more options, visit https://groups.google.com/d/optout.
# . Mailbox .
class AbstractMailbox(models.Model):
id = models.AutoField(primary_key=True)
localpart = models.CharField(_('Localpart'), max_length=40)
localdomainfk = models.ForeignKey(Localdomain,  verbose_name=_('Domain'), db_column='localdomainfk', editable=('AL'))
accountfk = models.ForeignKey(Account, verbose_name=_('Account'), db_column='accountfk', editable=('UL', 'UR','AR'))
status = models.CharField(_('Status'), max_length=1, choices=
(('N', _('New')), ('E', _('Enabled')), ('L', _('Locked')), ('D', _('Disabled')), ('C', _('Closed'))),
default='N', editable=('UL',))
created = models.DateField(_('Created'), auto_now_add=True)
updated = models.DateField(_('Updated'), auto_now=True)
remarks = models.TextField(_('Remarks'),null=True, blank=True, editable=('UL',))
lifetime = TimedeltaField(_('Lifetime of Data'), max_length=10, default='360 days', editable=('UL', 'UE'))
class Meta:
abstract = True
managed = False # can't migrate -- using fake model 'mailbox_for_migration' for migration
db_table = 'mailbox'
verbose_name = _('Mailbox')
verbose_name_plural = _('Mailboxes')
ordering = ['localpart']
unique_together = ('localpart', 'localdomainfk')
def __str__(self):
##return self.localpart+ '@'+self.localdomainfk.name+' ['+self.type+']'  # trouble with account/pw reset
return self.localpart+ '@'+self.localdomainfk.name

class Mailbox(AbstractMailbox): # a generic mailbox
type = models.CharField('Typ', max_length=1, choices=
(('A', _('Alias')), ('M', _('Mailbox')), ('S', _('Systemalias'))), editable=False)
aoxuserid = models.IntegerField(_('IMAP Server User ID'), null=True, blank=True)
quota = models.PositiveSmallIntegerField(_('IMAP Server Quota'),null=True, blank=True)
aliastargetaddresses = NULLCharFieldM(_('Alias Targetaddress'), max_length=75)

class Meta:
managed = False # can't migrate -- using fake model 'mailbox_for_migration' for migration
db_table = 'mailbox'
unique_together = ('localpart', 'localdomainfk')

class AliasManager(models.Manager):
def get_queryset(self):
return super(AliasManager, self).get_queryset().filter(type='A')
def filter(self, *args, **kwargs):
if not ('localpart' in kwargs and 'localdomainfk' in kwargs):
return self.get_queryset().filter(*args, **kwargs)
return super(AliasManager, self).get_queryset().filter(*args, **kwargs)

class Alias(AbstractMailbox):   # alias
type = models.CharField('Typ', max_length=1, choices=
(('A', _('Alias')), ('M', _('Mailbox')), ('S', _('Systemalias'))), editable=False, default='A')
aliastargetaddresses = NULLEmailFieldM(_('Alias Targetaddress'), max_length=75)
objects = AliasManager()
class Meta:
managed = False # can't migrate -- using fake model 'mailbox_for_migration' for migration
db_table = 'mailbox'
verbose_name = _('Alias')
verbose_name_plural = _('Aliases')
unique_together = ('localpart', 'localdomainfk')

class ConcreteMailboxManager(models.Manager):
def get_queryset(self):
return super(ConcreteMailboxManager, self).get_queryset().filter(type='M')
def filter(self, *args, **kwargs):
if not ('localpart' in kwargs and 'localdomainfk' in kwargs):
return 

Re: Django Model | Relationship question. Student->School Class

2015-12-22 Thread 'Tom Evans' via Django users
On Tue, Dec 22, 2015 at 6:50 AM, Pemby  wrote:
> With this code for example.
>
> class Students(models.Model):
> first_name = models.CharField(max_length=30)
> last_name = models.CharField(max_length=30)
> classChoice1 = ?
> classChoice2 = ?
> classChouce3 = ?
>
> class Class(models.Model):
> class_name = models.CharField(max_length=30)
> class_discription = models.CharField(max_length=30)
>
>
> Say for example I have Nth students, S1 S2 S3 ... and Nth classes (as in
> college class) C1 C2 C3 ...
> And I want to create a relationship where each student can only be assigned
> to one class uniquely for each classChoice
> selected. How would I create that relationship?

Remove the classChoiceN fields from Students, and add a ManyToMany
between Student and Class (remember model class names should be
singular, so "Student", not "Students") using a through table with an
additional "choice" integer field.

The "choice" field should have a maximum value of 3, and you will want
unique_together constraints on the through table for (student, class)
and (student, choice) - you can't sign up for the same class twice,
and you can only have one of each choice.

Cheers

Tom

-- 
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/CAFHbX1LyMUkxqVnDBciMZv39fvg5Ly9H%2BLWgp63RRonYoxKZuQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.