Re: How to implement clean() for a model with ManyToMany fields?

2015-10-17 Thread John Lawlor
You can, however, override the clean() method in a form for this model, and 
in clean() you have access to the form's fields and would be able to check 
and compare that all three of these fields are not simultaneously blank. 
You would not be able to do such processing in reverse--that is, you do not 
have access to a KalenderEintrag field on a Region, Kostenstelle, 
or Bereich form that had an KalenderEintrag inline form because those three 
models do not have a KalenderEintrag field in their model definition and so 
will not have a KalenderEintrag field in the clean_data dictionary.

On Monday, October 29, 2012 at 11:01:00 AM UTC-4, Carsten Fuchs wrote:
>
> Hi all, 
>
> using Django 1.3.1, I use a model like this: 
>
>
> class KalenderEintrag(models.Model): 
>  id   = models.AutoField(primary_key=True) 
>  von  = models.DateField(verbose_name=u"\u200Bvon") 
>  bis  = models.DateField(verbose_name=u"\u200Bbis") 
>  text = models.CharField(max_length=80) 
>  farbe= models.CharField(max_length=20, blank=True) 
>  regionen = models.ManyToManyField(Region,   null=True, 
> blank=True) 
>  kstellen = models.ManyToManyField(Kostenstelle, null=True, 
> blank=True) 
>  bereiche = models.ManyToManyField(Bereich,  null=True, 
> blank=True) 
>
>  def clean(self): 
>  if not self.regionen and not self.kstellen and not self.bereiche: 
>  raise ValidationError("This calender entry won't be 
> displayed anywhere.") 
>
>
> What I would like to do in clean() is making sure that not all three 
> ManyToMany fields are empty/blank all at the same time. 
>
> However, it doesn't work as shown above: 
>
> With pre-existing KalenderEintrag entries whose regionen, kstellen and 
> bereiche are all empty, the "if not self.regionen and not ..." does not 
> trigger. 
>
> When I try to newly create a KalenderEintrag in the admin, the "if not 
> self.regionen and not ..." line raises a ValueError exception: 
> "'KalenderEintrag' instance needs to have a primary key value before a 
> many-to-many relationship can be used." 
>
> How can I properly implement clean() to check the three ManyToMany 
> fields for non-empty contents? 
>
> 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 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/462ae916-1ed6-42f7-bcc2-ef99a1aa7198%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ValueError: save() prohibited to prevent data loss due to unsaved related object

2015-10-17 Thread Tim Graham
Do you have code that worked before (didn't result in data loss) but 
doesn't work now? If so, it could be a bug in Django.

On Friday, October 16, 2015 at 8:30:07 PM UTC-4, Mike Dewhirst wrote:
>
> I think I understand this error and I like what it does. My question is 
> ... 
>
> What is the necessary coding paradigm when you have all sorts of m:1, 
> 1:m and m:m relationships and need to create those objects when they 
> don't exist when saving a new central object? 
>
> I'm moving from 1.7.x to 1.8.5 and this error seems like a show-stopper 
> at the moment. 
>
> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a96af71f-3ad2-4789-9c91-c297f5cf4f89%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Exchange models between apps

2015-10-17 Thread svewa
Thanks, this was it, I tried this too, but then my IDE told me that it can 
not find this package so I assumed this will not work, but it works. Very 
strange...


On Saturday, October 17, 2015 at 3:58:05 PM UTC+2, Robin Lery wrote:
>
> Can u try this
> from userprofile.models import UserProfile
> On 17 Oct 2015 19:24, "svewa"  wrote:
>
>> Hello everyone,
>>
>> I have a problem with using models between django apps. In my project I 
>> have an app called *userprofile *containing a model *UserProfile*. In 
>> another app where I have a model *Object *I want to use my *UserProfile 
>> *model 
>> to give the *Object *an owner like so:
>>
>> *from mysite.userprofile.models import UserProfile*
>> ...
>> *class Object(models.Model):*
>> * owner = models.ForeignKey(UserProfile)*
>>
>> but importing the module userprofile fails:
>>
>> *ImportError: No module named userprofile.models*
>>
>> although my project root mysite is in the python path and my IDE is able 
>> to interpret the import statement. Of course I've registered the apps in my 
>> settings.py. Any hints what the problem is or do I ignore something that is 
>> a common technique to exchange models between apps?
>>
>> Any help is appreciated, many thanks in advance annd best regards,
>>
>> svewa 
>>
>> -- 
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/6e09a837-2505-4148-aa71-0a0ff1b9c268%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/93294a1f-0f96-4c9b-8058-9d7f8361371f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to develop a frontend web app for using REST services

2015-10-17 Thread kk

Hi again,
Xavier, I have gone through the main DRF documentation and also seen 
your blog.
I am wondering if you can send me an off line email which can explain 
the relation between serializer and viewset?
I have not got the concept clear, I am beginner to REST and all I 
understand is that the response is generally in form of json.

happy hacking.
Krishnakant.


On Friday 16 October 2015 03:39 PM, Xavier Ordoquy wrote:

Hi,

I wrote a short blog post about getting most of Django REST framework 
without using Django models.

https://medium.com/@linovia/django-rest-framework-viewset-when-you-don-t-have-a-model-335a0490ba6f

You will loose the integration with the Django Models and will need to 
do a few things by yourself (pagination for example) but it’s still 
perfectly possible to do that.
Note that most of the documentation covers Django Models because it’s 
where most of the options are. When you don’t use them, it’s up to the 
developers to provide the content which will be very different from a 
project to another.


Hope this will help,

Regards,
Xavier,
Linovia.


Le 16 oct. 2015 à 12:00, kk > a écrit :


hello again,
I haven't got my doubts solved but a few got added.
I was again going through the tutorial on Django REST framework.
I am trying to know if I can use a serialiser without tying it to the 
DJango ORM or for that matter without tying it to any thing?
I prefer using SQLAlchemy and get the data out using sql expression 
language.
Then I would like to convert this data to json format for sending as 
response.

Is this possible?
Happy hacking.
Krishnakant


On Friday 16 October 2015 11:39 AM, kk wrote:

Dear all.
I got some very important suggestions from members of this list on 
using Django for an accounting and inventory system, including Point 
of Sale.

After the POS topic was discussed,
OUr team decided to write a RESTfull server with all the business 
logic in API.
We plan to do this using some thing like Flask micro framework and 
then write a complete web app using Django to consume these services.

Of course it could be argued that why not use Django REST framework?
But here I am a bit surprised as well as a bit disappointed.
Contrary to what we have all seen and experienced about Django's 
documentation, the rest framework is not at all comprehensively 
documented.

I am still not totally understood the use of
|serializers.HyperlinkedModelSerializer. viewset is also not totally 
explained properly. the tutorial is pretty fast and confusing. I 
think a better example would have served it more understandable. Or 
perhaps the documentation there asumed that every one who reads it 
is a Django as well as REST expert, even then it is confusing. Any 
ways coming back to the topic. So What suggestions could I get about 
my main query? happy hacking. Krishnakant. |



--
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/5620CACC.2060702%40gmail.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/9872C498-CD0B-44A3-B64E-62A34F312C02%40linovia.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/56225AD3.6010205%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Importing models from another app?

2015-10-17 Thread Gergely Polonkai
How does it fail, what is the error message? My first guess is that you
should omit "mysite" from your import line, but without the exact message
it's hard to tell.

Best,
Gergely
On 17 Oct 2015 15:52, "svewa"  wrote:

> Hello everyone,
>
> I have a question about the model interaction between different django
> apps. In my project I have an app called *userprofile* containing my
> *UserProfile* model. In another app I have an *Object* model, which of
> course should have an owner. My idea is to give the *Object* class a
> field:
>
> *owner = models.ForeignKey(Userprofile)*
>
> but the import:
>
> *from mysite.userprofile.models import UserProfile*
>
> *fails*
>
> --
> 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/15ac9e1c-20a5-4a8c-a68b-6c05eefb6d78%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/CACczBUKQcDEtTJZXYkj5ySiujmnCCsgnxHh0hQ9j_GNHVHd-0A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to develop a frontend web app for using REST services

2015-10-17 Thread kk
Hi Xavier, well I am just not using the Django ORM.  That does not mean 
I am not going to use ORM at all.
I will be using sqlalchemy which my team is very proficient with when it 
comes to do even complex tasks.

In addition we will be using baked queries etc for performance enhancements.
So I guess the approach you suggested will be good.
I will ask more questions after reading your blog, but thanks again.
Happy hakcing.
Krishnakant.



On Friday 16 October 2015 03:39 PM, Xavier Ordoquy wrote:

Hi,

I wrote a short blog post about getting most of Django REST framework 
without using Django models.

https://medium.com/@linovia/django-rest-framework-viewset-when-you-don-t-have-a-model-335a0490ba6f

You will loose the integration with the Django Models and will need to 
do a few things by yourself (pagination for example) but it’s still 
perfectly possible to do that.
Note that most of the documentation covers Django Models because it’s 
where most of the options are. When you don’t use them, it’s up to the 
developers to provide the content which will be very different from a 
project to another.


Hope this will help,

Regards,
Xavier,
Linovia.


Le 16 oct. 2015 à 12:00, kk > a écrit :


hello again,
I haven't got my doubts solved but a few got added.
I was again going through the tutorial on Django REST framework.
I am trying to know if I can use a serialiser without tying it to the 
DJango ORM or for that matter without tying it to any thing?
I prefer using SQLAlchemy and get the data out using sql expression 
language.
Then I would like to convert this data to json format for sending as 
response.

Is this possible?
Happy hacking.
Krishnakant


On Friday 16 October 2015 11:39 AM, kk wrote:

Dear all.
I got some very important suggestions from members of this list on 
using Django for an accounting and inventory system, including Point 
of Sale.

After the POS topic was discussed,
OUr team decided to write a RESTfull server with all the business 
logic in API.
We plan to do this using some thing like Flask micro framework and 
then write a complete web app using Django to consume these services.

Of course it could be argued that why not use Django REST framework?
But here I am a bit surprised as well as a bit disappointed.
Contrary to what we have all seen and experienced about Django's 
documentation, the rest framework is not at all comprehensively 
documented.

I am still not totally understood the use of
|serializers.HyperlinkedModelSerializer. viewset is also not totally 
explained properly. the tutorial is pretty fast and confusing. I 
think a better example would have served it more understandable. Or 
perhaps the documentation there asumed that every one who reads it 
is a Django as well as REST expert, even then it is confusing. Any 
ways coming back to the topic. So What suggestions could I get about 
my main query? happy hacking. Krishnakant. |



--
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/5620CACC.2060702%40gmail.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/9872C498-CD0B-44A3-B64E-62A34F312C02%40linovia.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/56225487.2070208%40gmail.com.
For more options, visit 

Re: Exchange models between apps

2015-10-17 Thread Robin Lery
Can u try this
from userprofile.models import UserProfile
On 17 Oct 2015 19:24, "svewa"  wrote:

> Hello everyone,
>
> I have a problem with using models between django apps. In my project I
> have an app called *userprofile *containing a model *UserProfile*. In
> another app where I have a model *Object *I want to use my *UserProfile *model
> to give the *Object *an owner like so:
>
> *from mysite.userprofile.models import UserProfile*
> ...
> *class Object(models.Model):*
> * owner = models.ForeignKey(UserProfile)*
>
> but importing the module userprofile fails:
>
> *ImportError: No module named userprofile.models*
>
> although my project root mysite is in the python path and my IDE is able
> to interpret the import statement. Of course I've registered the apps in my
> settings.py. Any hints what the problem is or do I ignore something that is
> a common technique to exchange models between apps?
>
> Any help is appreciated, many thanks in advance annd best regards,
>
> svewa
>
> --
> 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/6e09a837-2505-4148-aa71-0a0ff1b9c268%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/CA%2B4-nGpmq%2BTaH6jHG5AL%3DFNj9nQ0ouxNVJqKGAchDNv7MQkxvA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Exchange models between apps

2015-10-17 Thread svewa
Hello everyone,

I have a problem with using models between django apps. In my project I 
have an app called *userprofile *containing a model *UserProfile*. In 
another app where I have a model *Object *I want to use my *UserProfile *model 
to give the *Object *an owner like so:

*from mysite.userprofile.models import UserProfile*
...
*class Object(models.Model):*
* owner = models.ForeignKey(UserProfile)*

but importing the module userprofile fails:

*ImportError: No module named userprofile.models*

although my project root mysite is in the python path and my IDE is able to 
interpret the import statement. Of course I've registered the apps in my 
settings.py. Any hints what the problem is or do I ignore something that is 
a common technique to exchange models between apps?

Any help is appreciated, many thanks in advance annd best regards,

svewa 

-- 
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/6e09a837-2505-4148-aa71-0a0ff1b9c268%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Importing models from another app?

2015-10-17 Thread svewa
Hello everyone,

I have a question about the model interaction between different django 
apps. In my project I have an app called *userprofile* containing my 
*UserProfile* model. In another app I have an *Object* model, which of 
course should have an owner. My idea is to give the *Object* class a field:

*owner = models.ForeignKey(Userprofile)*

but the import:

*from mysite.userprofile.models import UserProfile*

*fails*

-- 
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/15ac9e1c-20a5-4a8c-a68b-6c05eefb6d78%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.