Re: Null constraint violations when saving objects with ForeignKey relationships

2013-06-14 Thread kvlulla
Hi Lukasz..

Thanks it was helpful..i was looking for something like this.

-Karan

On Sunday, December 27, 2009 12:50:05 PM UTC-8, Łukasz Balcerzak wrote:
>
> Hi there,
>
> Well, just try to make sure you are passing already saved instance (having 
> primary key set)
> into related model which has foreign key to the first one.
>
> Your approach:
>
> > from test.models import A,B
> > instA = A()
> > instB = B(a=instA)
> > 
> > Now I'm done with my parsing and am happy to save them to my database:
> > 
> > instA.save() # all good
> > instB.save() # fails with IntegrityError: null value in column "a_id"
> > violates not-null constraint
>
> Could easily be fixed:
>
> > from test.models import A,B
> > instA = A()
> > #instB = B(a=instA) # We will do that later
> > 
> > Now I'm done with my parsing and am happy to save them to my database:
> > 
> > instA.save() # all good
> > instB = B(a=instA) # Now is the time
> > instB.save() # shouldn't raise any exception
>
> This is common problem if you are trying to get use to ORM. I had many 
> problems with
> understanding Hibernate/JPA a while ago when coding in Java.
>
> IntegrityError was risen because instA was cached at instB (you may check 
> this by comparing instB.a.id and instB.__dict__), and changes in instA
> haven't been pushed. It's common approach for Object-Relation Mappers.
>
> It's probably tempting to prepare your objects first but preparing your 
> data before
> is even better. If there would be not too much confusion you can try to 
> use dicts as data
> storage first, then just pass it to the constructors of your models - just 
> a note, I do
> this quite frequently in some cases.
>
> But if you are not convinced and you really have to prepare objects first 
> you may simply
> set instA to instB just before calling ``save`` method at instB. I would 
> be:
>
> > from test.models import A,B
> > instA = A()
> > instB = B() # prepare but don't set instA yet
> > 
> > Now I'm done with my parsing and am happy to save them to my database:
> > 
> > instA.save() # all good
> > instB.a = instA # now we set instA, *after* it has proper pk already set
> > instB.save() # shouldn't raise any exception
>
>
> Hope it helps
>
> On Dec 26, 2009, at 7:12 PM, gmayer wrote:
>
> > Hi guys,
> > 
> > I'm new to Django but otherwise quite a seasoned python and sql
> > programmer. I'm baffled by django's foreign key id behaviour and as a
> > result stuck in my current coding project. Let me start immediately
> > with an example of what I'm trying to do. Assume two very simple
> > models:
> > 
> > class A(models.Model):
> >pass
> > class B(models.Model):
> >a = models.ForeignKey(A)
> > 
> > Now I need to create an instance of A and B without saving either of
> > them (I'm parsing a whack load of data and only want to commit objects
> > to the db once successfully parsed):
> > 
> > from test.models import A,B
> > instA = A()
> > instB = B(a=instA)
> > 
> > Now I'm done with my parsing and am happy to save them to my database:
> > 
> > instA.save() # all good
> > instB.save() # fails with IntegrityError: null value in column "a_id"
> > violates not-null constraint
> > 
> > On closer inspection the second line above fails because instB.a_id is
> > None, even though instB.a.id is defined. Why does django throw in a
> > duplicate, now stale instB.a_id field which, to make matters worse, is
> > used in generating the underlying SQL for instB.save() to result in
> > failure
> > 
> > Perhaps I'm just to n00b to use the correct semantics which avoid the
> > above issues... excuse me if that's the case.
> > 
> > Gunther
> > 
> > --
> > 
> > You received this message because you are subscribed to the Google 
> Groups "Django users" group.
> > To post to this group, send email to django...@googlegroups.com
> .
> > To unsubscribe from this group, send email to 
> django-users...@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 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: Django confusing issues DRIVING ME MAD. Please someone help?

2013-06-14 Thread sparky
*thanks Nikolas!!!* you help me resolve the issue. no idea why it effects 
reverse but my log file show an error with some middleware and resloved 
that issue and for some reason all urls started working again!

On Friday, June 14, 2013 6:45:08 PM UTC+1, sparky wrote:
>
> Hi, I'm wondering if anyone can help me with the following issues it's 
> really confusing me *(and others who have tried to help)*
>
> The question is here: 
> http://stackoverflow.com/questions/17113479/django-get-absolute-url-empty-in-production
>
> *But the summery is. *
>
> I'm using {{ item.get_absolute_url }} in a template. Within development 
> the rendered HTML looks like this:
>
> *http://127.0.0.1:8002/contacts/group/edit/36/*  - correct!
>
> On live production it's empty:
>
> *http://domain.com/*  - empty!
>
> Meaning I get a 'NoneType' error on ayhting that uses 
> self.get_absolute_url() function (only on production)  the code is 100% the 
> same on both machines I promise. Both on Django 1.5.1 and it 100% works in 
> dev (runserver) but on on Apache. 
>

-- 
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: Django confusing issues DRIVING ME MAD. Please someone help?

2013-06-14 Thread Nikolas Stevenson-Molnar
Ok, so something is happening to the name "reverse" in the global scope
between the time you're importing it at the top of the file and when
get_absolute_url is called. Search the file for instances of "reverse".
Are you importing anything else by that name? Or anything like "import
foo as reverse" or anywhere in the file is there anything like "reverse
= foo"?

Failing that, are you using "from foo import *" anywhere? If so, check
the modules you're doing an "import *" from and see if any of them are
using the name "reverse" in anyway.

_Nik

On 6/14/2013 3:33 PM, sparky wrote:
> Ok I have no idea whats happening, I took your advice and added the
> code below. then on production get_absolute_url starting working. I
> took it out and it stopped again. get_delete_url does not work either
> until I add in your debugging again WTF!
>
> def get_absolute_url(self):
> import logging
> from django.core.urlresolvers import reverse
> logging.debug(reverse)
> logging.debug(str)
> return reverse('contacts.views.group', args=[str(self.id)])
>
> def get_delete_url(self):
> return reverse('contacts.views.group_delete_confirm',
> args=[str(self.id)])
> -- 
> 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.
>  
>  

-- 
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: Django confusing issues DRIVING ME MAD. Please someone help?

2013-06-14 Thread sparky
Ok I have no idea whats happening, I took your advice and added the code 
below. then on production get_absolute_url starting working. I took it out 
and it stopped again. get_delete_url does not work either until I add in 
your debugging again WTF!

def get_absolute_url(self):
import logging
from django.core.urlresolvers import reverse
logging.debug(reverse)
logging.debug(str)
return reverse('contacts.views.group', args=[str(self.id)])

def get_delete_url(self):
return reverse('contacts.views.group_delete_confirm', 
args=[str(self.id)])

-- 
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: Django confusing issues DRIVING ME MAD. Please someone help?

2013-06-14 Thread Nikolas Stevenson-Molnar
It's hard to say without having the full source. If the data are
different on dev and production, it's possible there's a different
execution path, causing a problem on one but not the other. But you can
tell it's not an import problem, as that would raise an import error.
And it's not a problem with the URL itself, as execution doesn't make it
that far (and you'd get a NoReverseMatch exception).

Here's a diagnostic step to try. In get_absolute_url, re-import reverse,
then log (you'll need to set up logging if you haven't already) both
reverse and str (make sure str isn't the one that's None) and then do
the actual call:

def get_absolute_url(self):
from django.core.urlresolvers import reverse
logger.debug(reverse)
logger.debug(str)
return reverse('contacts.views.group', args=[str(self.id)])

What happens with that will give you some clues about where to look
next. If it succeeds, then the "reverse" name is being reassigned at the
global scope somewhere. If it fails and "str" is None, then it's being
reassigned. If reverse is still None, then something's up with your
Django install.

_Nik

On 6/14/2013 2:37 PM, sparky wrote:
> Hi Nikolas,
>
>
>  - Guessing from the stack trace you provided, either "reverse" or
> "str" are None (since those are the only two function calls on that line).
>
> yes that will be the issue, but why is it none in production and works
> (has a value) in django server?
> -- 
> 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.
>  
>  

-- 
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: Django confusing issues DRIVING ME MAD. Please someone help?

2013-06-14 Thread sparky
Hi Nikolas,


 - Guessing from the stack trace you provided, either "reverse" or "str" 
are None (since those are the only two function calls on that line).

yes that will be the issue, but why is it none in production and works (has 
a value) in django server?

-- 
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: Issues saving form data

2013-06-14 Thread Lucas Magnum
Hi Tom,

Maybe I can help you.
Skype: lmagnum92





[]'s

Lucas Magnum.


2013/6/14 Tom Russell 

> I am having some issues saving data from a form and not sure why since it
> was working just yesterday.
>
> Could someone take a look offline to give me some feedback on what I am
> doing wrong? It's a small project but this has me stumped. Also, is
> anyone available via skype to talk in regards to some of my issues?
>
> Thanks,
>
> 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 http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

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




Issues saving form data

2013-06-14 Thread Tom Russell
I am having some issues saving data from a form and not sure why since it
was working just yesterday.

Could someone take a look offline to give me some feedback on what I am
doing wrong? It's a small project but this has me stumped. Also, is
anyone available via skype to talk in regards to some of my issues?

Thanks,

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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django confusing issues DRIVING ME MAD. Please someone help?

2013-06-14 Thread Nikolas Stevenson-Molnar
Guessing from the stack trace you provided, either "reverse" or "str"
are None (since those are the only two function calls on that line). Is
there anywhere you are doing something like reverse = blah or str =
blah? Also, you could add a couple of debug statements prior to that
call to confirm which (if either) or these are ending up None.

_Nik

On 6/14/2013 10:45 AM, sparky wrote:
> Hi, I'm wondering if anyone can help me with the following issues it's
> really confusing me /(and others who have tried to help)/
>
> The question is here:
> http://stackoverflow.com/questions/17113479/django-get-absolute-url-empty-in-production
>
> *But the summery is. *
>
> I'm using {{ item.get_absolute_url }} in a template. Within
> development the rendered HTML looks like this:
>
> *http://127.0.0.1:8002/contacts/group/edit/36/*  - correct!
>
> On live production it's empty:
>
> *http://domain.com/*  - empty!
>
> Meaning I get a 'NoneType' error on ayhting that uses
> self.get_absolute_url() function (only on production)  the code is
> 100% the same on both machines I promise. Both on Django 1.5.1 and it
> 100% works in dev (runserver) but on on Apache.
> -- 
> 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.
>  
>  

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




Django confusing issues DRIVING ME MAD. Please someone help?

2013-06-14 Thread sparky
Hi, I'm wondering if anyone can help me with the following issues it's 
really confusing me *(and others who have tried to help)*

The question is here: 
http://stackoverflow.com/questions/17113479/django-get-absolute-url-empty-in-production

*But the summery is. *

I'm using {{ item.get_absolute_url }} in a template. Within development the 
rendered HTML looks like this:

*http://127.0.0.1:8002/contacts/group/edit/36/*  - correct!

On live production it's empty:

*http://domain.com/*  - empty!

Meaning I get a 'NoneType' error on ayhting that uses 
self.get_absolute_url() function (only on production)  the code is 100% the 
same on both machines I promise. Both on Django 1.5.1 and it 100% works in 
dev (runserver) but on on Apache. 

-- 
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: Django Basics

2013-06-14 Thread Andre Terra
You really *should* use a database, even if you use SQLite just for
learning. SQLite saves a .db file to your hard drive, but it's a RDBMS like
many other, albeit in simpler form.

Take a look at the tutorial[1] and if you have any questions, try googling,
asking here or on stackoverflow[2]


Cheers,
AT

[1] https://docs.djangoproject.com/en/dev/intro/tutorial01/
[2] http://www.stackoverflow.com/

On Thu, Jun 13, 2013 at 5:33 PM, Rafael E. Ferrero  wrote:

> you can perfectly do what you require without a database access, just read
> your dictionary on a view on views.py. If you need a database for small
> projects you can do your model on a sqlite database.
>
> you can start with google... are tons of tutorials.  In
> www.djangoproject.com you have a nice beginner tutorial and really deep
> information of all the framework, this is almost the only one manual that i
> read.
>
> cheers
>
>
>
> 2013/6/13 ambi 
>
>> I am totally new to Django framework and to python web project. Do I have
>> to user database for django to work or it can work with the flat files. My
>> requirement is to read values form dictionary and display it on a web page.
>>  My other question is where can i= read more about Django for beginners *
>> *
>>
>> --
>> 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.
>>
>>
>>
>
>
>
> --
> Rafael E. Ferrero
> Claro: (03562) 15514856
>
> --
> 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.
>
>
>

-- 
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: Django-Tastypie and MySQL

2013-06-14 Thread Sithembewena Lloyd Dube
Much better. I don't think that you have to put quotes when you define
player_club. Just go, player_club = models.ForeignKey(Club) - you want to
pass the Club model, not a string.

Regarding the question, if the player can only belong to one club, then a
foreignkey relationship is correct because it's a ManyToOne (Many Players,
One Club). If the player can belong to many clubs, and a club can have many
players, then use a ManyToMany relationship (Many Players in one Club, Many
Clubs for One Player).

See the following, imagine that the Article is a Player and the Publication
is a Club:
https://docs.djangoproject.com/en/1.5/topics/db/examples/many_to_many/


On Fri, Jun 14, 2013 at 6:20 PM, Hélio Miranda  wrote:

> Ok, so what I did was this:
> Código (Python):
> class Player(models.Model):
> player_name = models.CharField(max_length=200)
> player_age = models.CharField(max_length=200)
> player_club = models.ForeignKey('Club')
>
> class Club(models.Model):
> club_name = models.CharField(max_length=200)
>
> It seems that it is working, but I'm not here set up a many to many.
>
> I have to add the option ManyToManyField at some place?
> Am I 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.
>
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Regards,
Sithu Lloyd Dube

-- 
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: Newbie with Demo issues

2013-06-14 Thread Sithembewena Lloyd Dube
Hi Strat,

Tom is right - the issue is the name of the view in your template. Reverse
takes the name of your view and builds it's url. In this case, you are
calling the view 'detail/' (with a trailing slash) instead of 'detail'.

Cheers,
Lloyd


On Fri, Jun 14, 2013 at 3:42 PM, Tom Evans  wrote:

> On Fri, Jun 14, 2013 at 10:12 AM, Strat Parrott 
> wrote:
> >
> >
> > I have done the tutorial three times and everything is fine up until I
> get
> > to Tutorial 3
> > https://docs.djangoproject.com/en/1.5/intro/tutorial03/
> >
> >
> > I must be missing something but at this point I've done it all three
> times
> > so I'm not sure what the issue is. I've tried looking up solutions to 'No
> > reverse' and they are beyond me at this time.
> >
> >
> > >>>
> >
> > Now let’s update our index view in polls/views.py to use the template:
> >
> > from django.http import HttpResponse
> > from django.template import Context, loader
> >
> > from polls.models import Poll
> >
> > def index(request):
> > latest_poll_list = Poll.objects.order_by('-pub_date')[:5]
> > template = loader.get_template('polls/index.html')
> > context = Context({
> > 'latest_poll_list': latest_poll_list,
> > })
> > return HttpResponse(template.render(context))
> >
> > That code loads the template called polls/index.html and passes it a
> > context. The context is a dictionary mapping template variable names to
> > Python objects.
> >
> > Load the page by pointing your browser at “/polls/”, and you should see a
> > bulleted-list containing the “What’s up” poll from Tutorial 1. The link
> > points to the poll’s detail page.
> >
> > <<<
> >
> >
> > Once I set that view I get
> >
> >
> > NoReverseMatch at /polls/
> >
> > Reverse for 'detail/' with arguments '(2L,)' and keyword arguments '{}'
> > not found.
> >
> > Request Method:GET
> > Request URL:http://127.0.0.1:8000/polls/
> > Django Version:1.5.1
> > Exception Type:NoReverseMatch
> > Exception Value:
> >
> > Reverse for 'detail/' with arguments '(2L,)' and keyword arguments '{}'
> > not found.
>
>
> What name did you give the url in your urls.py? Was it "detail/" or
> was it "detail".
>
> 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 http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>


-- 
Regards,
Sithu Lloyd Dube

-- 
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: Django-Tastypie and MySQL

2013-06-14 Thread Hélio Miranda
Ok, so what I did was this:
Código (Python):
class Player(models.Model):
player_name = models.CharField(max_length=200)
player_age = models.CharField(max_length=200)
player_club = models.ForeignKey('Club')
   
class Club(models.Model):
club_name = models.CharField(max_length=200)

It seems that it is working, but I'm not here set up a many to many.

I have to add the option ManyToManyField at some place?
Am I 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.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django-Tastypie and MySQL

2013-06-14 Thread Sithembewena Lloyd Dube
I meant, delete the PlayerClub linking table/ model. The foreignkey
relationship takes care of that need.


On Fri, Jun 14, 2013 at 4:41 PM, Sithembewena Lloyd Dube
wrote:

> Hey,
>
> The player belongs to a club. So in the player model you should have
>
> player_club = models.ForeignKey(Club)
>
> then remove the foreign key in the Club model. Also, notice casing - your
> variable names should be lowercase and if it's more than one word, join it
> with underscores. It's Python convention.
>
>
> On Fri, Jun 14, 2013 at 2:51 PM, Hélio Miranda  wrote:
>
>> After reading a bit what I did was the following:
>> Código (Python):
>> from django.db import models
>> class Player(models.Model):
>> #idPlayer = models.AutoField(primary_key=True)
>> PlayerName = models.CharField(max_length=200)
>> PlayerAge = models.CharField(max_length=200)
>> #Clubs = models.ManyToManyField('Club', through='PlayerClub', null =
>> True, blank = True)
>>
>> class Club(models.Model):
>> #idClub = models.AutoField(primary_key=True)
>> ClubName = models.CharField(max_length=200)
>> Players = models.ManyToManyField(Player, through='PlayerClub')
>>
>> class PlayerClub(models.Model):
>> Player = models.ForeignKey(Player)
>> Club = models.ForeignKey(Club)
>>
>> But for example when I am inserting the player wanted to say that club he
>> belongs, as is how do I right?
>> What I wanted to do was enter the club, and when I select the player to
>> enter the club he belongs.
>> When to see the player, the data comes from the player and the club that
>> belongs to consult a club and when I say that players belong to this club.
>> I'm going the right way?
>>
>> --
>> 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.
>>
>>
>>
>
>
>
> --
> Regards,
> Sithu Lloyd Dube
>



-- 
Regards,
Sithu Lloyd Dube

-- 
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: User authentication with either username or email.

2013-06-14 Thread Tom Evans
On Fri, Jun 14, 2013 at 3:29 PM, shashank sandela
 wrote:
> As you can see in the views.py I did import the class
> EmailOrUsernameModelBackend.

OK. But you mustn't import that class, you must allow django to import
it itself, and then django will use it when authenticating users.

You do this by specifying the class in
settings.AUTHENTICATION_BACKENDS, and then calling the function
authenticate() in your view, which you should import from
django.contrib.auth.

You are trying to call the method authenticate on your auth backend
directly. Do not do this, it is incorrect. It is because of this you
are getting the error "'User' object has no attribute 'backend'".

Please notice the difference between the **function** authenticate()
and the **method** authenticate() on your auth backend.

Your view should look like the view linked below:

https://docs.djangoproject.com/en/1.5/topics/auth/default/#how-to-log-a-user-in

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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Django-Tastypie and MySQL

2013-06-14 Thread Sithembewena Lloyd Dube
Hey,

The player belongs to a club. So in the player model you should have

player_club = models.ForeignKey(Club)

then remove the foreign key in the Club model. Also, notice casing - your
variable names should be lowercase and if it's more than one word, join it
with underscores. It's Python convention.


On Fri, Jun 14, 2013 at 2:51 PM, Hélio Miranda  wrote:

> After reading a bit what I did was the following:
> Código (Python):
> from django.db import models
> class Player(models.Model):
> #idPlayer = models.AutoField(primary_key=True)
> PlayerName = models.CharField(max_length=200)
> PlayerAge = models.CharField(max_length=200)
> #Clubs = models.ManyToManyField('Club', through='PlayerClub', null =
> True, blank = True)
>
> class Club(models.Model):
> #idClub = models.AutoField(primary_key=True)
> ClubName = models.CharField(max_length=200)
> Players = models.ManyToManyField(Player, through='PlayerClub')
>
> class PlayerClub(models.Model):
> Player = models.ForeignKey(Player)
> Club = models.ForeignKey(Club)
>
> But for example when I am inserting the player wanted to say that club he
> belongs, as is how do I right?
> What I wanted to do was enter the club, and when I select the player to
> enter the club he belongs.
> When to see the player, the data comes from the player and the club that
> belongs to consult a club and when I say that players belong to this club.
> I'm going the right way?
>
> --
> 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.
>
>
>



-- 
Regards,
Sithu Lloyd Dube

-- 
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: User authentication with either username or email.

2013-06-14 Thread shashank sandela
Sorry. The error was: 

AttributeError at /authentication/

'User' object has no attribute 'backend'

-- 
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: User authentication with either username or email.

2013-06-14 Thread shashank sandela
As you can see in the views.py I did import the class *
EmailOrUsernameModelBackend.*
*
*
Now when I used " *user = 
EmailOrUsernameModelBackend().authenticate(username=username, 
password=password) *"
It gave an error saying: 
AttributeError at /tangle/auth/

'User' object has no attribute 'backend'

-- 
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: User authentication with either username or email.

2013-06-14 Thread Enyert Viñas

El 14/06/2013 07:26 a.m., shashank sandela escribió:

unbound method authenticate() must be called with EmailOrUsernameModelBackend 
instance as first argument (got nothing instead)
Hi. Remember that you must import a function before you call it. This is 
a reference to authentication in Django 
https://docs.djangoproject.com/en/1.5/topics/auth/default/#how-to-log-a-user-in 



Regards.

--
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: Newbie with Demo issues

2013-06-14 Thread Tom Evans
On Fri, Jun 14, 2013 at 10:12 AM, Strat Parrott  wrote:
>
>
> I have done the tutorial three times and everything is fine up until I get
> to Tutorial 3
> https://docs.djangoproject.com/en/1.5/intro/tutorial03/
>
>
> I must be missing something but at this point I've done it all three times
> so I'm not sure what the issue is. I've tried looking up solutions to 'No
> reverse' and they are beyond me at this time.
>
>
> >>>
>
> Now let’s update our index view in polls/views.py to use the template:
>
> from django.http import HttpResponse
> from django.template import Context, loader
>
> from polls.models import Poll
>
> def index(request):
> latest_poll_list = Poll.objects.order_by('-pub_date')[:5]
> template = loader.get_template('polls/index.html')
> context = Context({
> 'latest_poll_list': latest_poll_list,
> })
> return HttpResponse(template.render(context))
>
> That code loads the template called polls/index.html and passes it a
> context. The context is a dictionary mapping template variable names to
> Python objects.
>
> Load the page by pointing your browser at “/polls/”, and you should see a
> bulleted-list containing the “What’s up” poll from Tutorial 1. The link
> points to the poll’s detail page.
>
> <<<
>
>
> Once I set that view I get
>
>
> NoReverseMatch at /polls/
>
> Reverse for 'detail/' with arguments '(2L,)' and keyword arguments '{}'
> not found.
>
> Request Method:GET
> Request URL:http://127.0.0.1:8000/polls/
> Django Version:1.5.1
> Exception Type:NoReverseMatch
> Exception Value:
>
> Reverse for 'detail/' with arguments '(2L,)' and keyword arguments '{}'
> not found.


What name did you give the url in your urls.py? Was it "detail/" or
was it "detail".

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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: User authentication with either username or email.

2013-06-14 Thread Tom Evans
On Fri, Jun 14, 2013 at 12:56 PM, shashank sandela
 wrote:
> Hi,
>
> I created a backends.py in my project folder.
>
> backends.py ::
>
> from django.conf import settings
> from django.contrib.auth.models import User
>
> class EmailOrUsernameModelBackend(object):
> def authenticate(self, username=None, password=None):
> if '@' in username:
> kwargs = {'email': username}
> else:
> kwargs = {'username': username}
> try:
> user = User.objects.get(**kwargs)
> if user.check_password(password):
> return user
> except User.DoesNotExist:
> return None
>
> def get_user(self, user_id):
> try:
> return User.objects.get(pk=user_id)
> except User.DoesNotExist:
> return None
>
> And in the views.py,
>
> from django.contrib import auth
> from django.contrib.auth.models import User
> from tangle.backends import EmailOrUsernameModelBackend
>
> def authentication(request):
> username = request.POST.get('username', '')
> password = request.POST.get('password', '')
> user = authenticate(username=username, password=password)
> if user is not None:
> auth.login(request, user)
> return HttpResponseRedirect('/loggedin/')
> else:
> return HttpResponseRedirect('/invalid_login')
>
> Settings.py
>
> AUTHENTICATION_BACKENDS = (
> 'backends.EmailOrUsernameModelBackend',
> 'django.contrib.auth.backends.ModelBackend'
> )
>
> Now when I login using either username or email it shows an error "global
> name 'authenticate' is not defined"

Yes. You must import this function before you can call it:

https://docs.djangoproject.com/en/1.5/topics/auth/default/#how-to-log-a-user-in

>
> So, I used
> user = EmailOrUsernameModelBackend.authenticate(username=username,
> password=password)
>
> It shows
>
> TypeError at /authentication/
>
> unbound method authenticate() must be called with
> EmailOrUsernameModelBackend instance as first argument (got nothing instead)
>

The EmailOrUsernameModelBackend.authenticate() method is an instance
method. You must call it with an instance of
EmailOrUsernameModelBackend, not as a class method. In fact, you do
not call it at all, you list the auth backends in settings.py, and
allow django to instantiate an instance of the class and call
authenticate on it.

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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Using Fabric to clear database records

2013-06-14 Thread Sithembewena Lloyd Dube
Thank you, Avraham.


On Fri, Jun 14, 2013 at 2:26 PM, Avraham Serour  wrote:

> manage.py flush
>
>
> On Fri, Jun 14, 2013 at 3:16 PM, Sithembewena Lloyd Dube <
> zebr...@gmail.com> wrote:
>
>> Greetings,
>>
>> I've got a Django 1.5.1. project where I have a Video model (basically
>> saving video metadata). I would like to create a fabfile in my project
>> folder so that when I run 'fab production refresh', the list of videos
>> saved in the production environment (Amazon EC2) should be cleared out and
>> any new videos added should have ids starting from 1 again.
>>
>> Any ideas on implementing this?
>>
>> --
>> Regards,
>> Sithu Lloyd Dube
>>
>> --
>> 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.
>>
>>
>>
>
>  --
> 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.
>
>
>



-- 
Regards,
Sithu Lloyd Dube

-- 
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: Django-Tastypie and MySQL

2013-06-14 Thread Hélio Miranda
After reading a bit what I did was the following:
Código (Python):
from django.db import models
class Player(models.Model):
#idPlayer = models.AutoField(primary_key=True)
PlayerName = models.CharField(max_length=200)
PlayerAge = models.CharField(max_length=200)
#Clubs = models.ManyToManyField('Club', through='PlayerClub', null = 
True, blank = True)
   
class Club(models.Model):
#idClub = models.AutoField(primary_key=True)
ClubName = models.CharField(max_length=200)
Players = models.ManyToManyField(Player, through='PlayerClub')
   
class PlayerClub(models.Model):
Player = models.ForeignKey(Player)
Club = models.ForeignKey(Club)

But for example when I am inserting the player wanted to say that club he 
belongs, as is how do I right?
What I wanted to do was enter the club, and when I select the player to 
enter the club he belongs.
When to see the player, the data comes from the player and the club that 
belongs to consult a club and when I say that players belong to this club.
I'm going the right way?

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




User authentication with either username or email.

2013-06-14 Thread shashank sandela
Hi,

I created a backends.py in my project folder.

backends.py ::

*from django.conf import settings*
*from django.contrib.auth.models import User*
*
*
*class EmailOrUsernameModelBackend(object):*
*def authenticate(self, username=None, password=None):*
*if '@' in username:*
*kwargs = {'email': username}*
*else:*
*kwargs = {'username': username}*
*try:*
*user = User.objects.get(**kwargs)*
*if user.check_password(password):*
*return user*
*except User.DoesNotExist:*
*return None*
*
*
*def get_user(self, user_id):*
*try:*
*return User.objects.get(pk=user_id)*
*except User.DoesNotExist:*
*return None*
*
*
And in the views.py,

*from django.contrib import auth*
*from django.contrib.auth.models import User*
*from tangle.backends import EmailOrUsernameModelBackend*
*
*
*def authentication(request):*
*username = request.POST.get('username', '')*
*password = request.POST.get('password', '')*
*user = authenticate(username=username, password=password)*
*if user is not None:*
*auth.login(request, user)*
*return HttpResponseRedirect('/loggedin/')*
*else:*
*return HttpResponseRedirect('/invalid_login')*
*
*
Settings.py

*AUTHENTICATION_BACKENDS = (*
*'backends.EmailOrUsernameModelBackend',*
*'django.contrib.auth.backends.ModelBackend'*
*)*
*
*
Now when I login using either username or email it shows an error "global 
name 'authenticate' is not defined"

So, I used 
*user = EmailOrUsernameModelBackend.authenticate(username=username, 
password=password)*
*
*
It shows

TypeError at /authentication/

unbound method authenticate() must be called with EmailOrUsernameModelBackend 
instance as first argument (got nothing instead)

Can anyone help me out in solving the issue?

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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Using Fabric to clear database records

2013-06-14 Thread Avraham Serour
manage.py flush


On Fri, Jun 14, 2013 at 3:16 PM, Sithembewena Lloyd Dube
wrote:

> Greetings,
>
> I've got a Django 1.5.1. project where I have a Video model (basically
> saving video metadata). I would like to create a fabfile in my project
> folder so that when I run 'fab production refresh', the list of videos
> saved in the production environment (Amazon EC2) should be cleared out and
> any new videos added should have ids starting from 1 again.
>
> Any ideas on implementing this?
>
> --
> Regards,
> Sithu Lloyd Dube
>
> --
> 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.
>
>
>

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




Using Fabric to clear database records

2013-06-14 Thread Sithembewena Lloyd Dube
Greetings,

I've got a Django 1.5.1. project where I have a Video model (basically
saving video metadata). I would like to create a fabfile in my project
folder so that when I run 'fab production refresh', the list of videos
saved in the production environment (Amazon EC2) should be cleared out and
any new videos added should have ids starting from 1 again.

Any ideas on implementing this?

-- 
Regards,
Sithu Lloyd Dube

-- 
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: Django-Tastypie and MySQL

2013-06-14 Thread Sithembewena Lloyd Dube
Hi Hélio,

I happen to be using Tastypie for the first time as well and so far, the
documentation is comprehensive enough. You could start here:

http://django-tastypie.readthedocs.org/en/latest/tutorial.html
http://django-tastypie.readthedocs.org/en/latest/cookbook.html
http://django-tastypie.readthedocs.org/en/latest/resources.html#id11

Just FYI, the documentation assumes that one has working knowledge of
Django.


On Thu, Jun 13, 2013 at 4:16 PM, Hélio Miranda  wrote:

> I'm trying to make an application using django and mysql tastypie.
> Does anyone have any examples using the three technologies that can tell
> me for me to see, and follow me?
>
> thank you
>
> --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Regards,
Sithu Lloyd Dube

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




Django list_filter in Admin

2013-06-14 Thread francescobocca...@libero.it
Hi all,
i would like to add in my admin page a custom filter that can allow me to 
select all user that doesn't belong to none groups.
If i add :

list_filter = ('groups')

it show me a filter in the right part af admin interface:

By group

All
group1
group2

i would like to add :

All
None (0)
group1
group2

is it possible?

Thanks

Francesco 

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




display selected item in template using Django

2013-06-14 Thread roopasingh250


PERSON_ACTIONS = (
('1', '01.Allowed to rest and returned to class'),
('2', '02.Contacted parents /guardians'),
('3', '02a.- Unable to Contact'),
('4', '02b.Unavailable - left message'),)
class PersonActionsForm(forms.ModelForm):

action = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), 
choices=PERSON_ACTIONS, required=False, label= u"Actions")

models.py
class Actions(models.Model): reportperson = 
models.ForeignKey(ReportPerson)action 
= models.IntegerField('Action type') 

views.py
def actions(request): 
'' 
action= Actions.objects.filter(reportperson=person_id) 
action_checked_list = action.values_list('action',flat=True) 
actionform = PersonActionsForm(initial={'action': action_checked_list}) 
 
return render_to_response('action.html', { 'actionform':actionform, 
},context_instance
=RequestContext(request))

I am keeping the forms choices in PersonActionsForm,and saving the choice 
values in database as 1,2,3 and 4.

In views.py,i queried the entire row and taken the entire form for 
display.So now the checked choices and unchecked choices are render in 
template.

Instead,i want to display the checked choice alone in to display and while 
display check box is not necessary.I want to know how to do this.

Need help.

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 http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.