Re:

2013-11-04 Thread Leonardo Giordani
Hi,

please include the relevant part of the models and the views when asking
such questions, otherwise it is very difficult for people to help you.

I'd say that the problem is in the query extracting the values you are
showing. You say you do not want number 22 to appear twice: if  there are
two entries with the same number it is clearly not a primary key, so
probably you are filtering on the wrong column.

Leo

Leonardo Giordani
Author of The Digital Cat 
My profile on About.me  - My GitHub
page- My Coderwall
profile 


2013/11/1 Harjot Mann 

> The following picture is displaying is showing the html template
> results in which it is shown that the number 22 repeats two times and
> it is having separate ref numbers, and I want that the repeated values
> should not appear twice.
> ex: some amount line 5301 is appearing in both but i dnt need it, I
> only need it once.
> any idea how to do it?
>
>
> http://202.164.53.122/~harjotmann/errors/susreg.png
>
> --
> Harjot Kaur Mann
> Blog: http://harjotmann.wordpress.com/
> Daily Dairy: http://harjotmann.wordpress.com/daily-diary/
>
> --
> 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/CAB0GQhBLO75C3KF-g0QVxzh2wWUbnqmJ6VmZvEFp%3DyY9ur2FaQ%40mail.gmail.com
> .
> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BO%3Ddu1b8T61ToJZNgnYzM7vBpNXqH82cVD%3DfdxT0qgTLTw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: TypeError: can't subtract offset-naive and offset-aware datetimes

2013-11-04 Thread Leonardo Giordani
Take a look at

https://docs.djangoproject.com/en/dev/topics/i18n/timezones/#naive-and-aware-datetime-objects

Basically you need to fix datetime objects adding a timezone.

Regards,

Leo

Leonardo Giordani
Author of The Digital Cat 
My profile on About.me  - My GitHub
page- My Coderwall
profile 


2013/11/4 NHT 

> In poll app, I set Time_Zone='Asia/Kolkata' and USE_TZ=True in settings.py
> file.
> In models.py file,
>
> import datetime
> from django.utils import timezone
> from django.db import models
>
> class Poll(models.Model):
> question = models.CharField(max_length=200)
> pub_date = models.DateTimeField('date published')
> def __unicode__(self):
> return self.question
> def was_published_recently(self):
> return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
>
> class Choice(models.Model):
> poll = models.ForeignKey(Poll)
> choice_text = models.CharField(max_length=200)
> votes = models.IntegerField(default=0)
> def __unicode__(self):
> return self.choice_text
>
> when I try to run this code , I am getting the above error.I am using
> Windows 8. Please help!!
>
>  --
> 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/979241e3-43ab-41fb-9148-4a3fd9022c15%40googlegroups.com
> .
> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BOnJ6zgCnxLbGEZzPWOM6ii7HUU02U7CaLkMp4MEvNVtTw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Tutorials

2013-11-04 Thread Jasvir Singh
On Sat, Oct 26, 2013 at 6:35 PM, Jasvir Singh  wrote:
> Here is link of my tutorials
> http://goo.gl/3jPaf7

Now these tutorials are shifted to my personal domain.
http://www.jsgrewal.com/tutorials/django/

@all, critical reviews are needed.

-- 

Jasvir Singh Grewal
Blog:http://jasvirsinghgrewal91.wordpress.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To 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/CAN_O85vDtM9rxyR896Ndc7dxBiwaCaT-CubOn0bR8tDUPfy3YA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re:

2013-11-04 Thread Rafael E. Ferrero
I think that if u take a background image like a User Property then u must
to extend User Model then make a one to one relationship from that to a
with backgrounds model. With this your extended user model will have only
one field who can take just one value... the ID of a Background Image.



2013/11/3 Lee Hinde 

> You want there to be only one BackgroundImage record marked as
> 'using_image' for a given user. I'm saying you should add a field to your
> User table that tracks their BackgroundImage.
>
> On Nov 3, 2013, at 2:43 PM, Aamu Padi  wrote:
>
> Thank you for the reply Lee. But could please elaborate a little more. :)
>
>
> On Mon, Nov 4, 2013 at 2:48 AM, Lee Hinde  wrote:
>
>>
>> On Nov 3, 2013, at 12:23 PM, Aamu Padi  wrote:
>>
>> > How to make a model with a yes/no field, if yes that particular object
>> (image) will be used as the background, and no other image will be selected.
>> >
>> > I have come with this model:
>> >
>> > class BackgroundImage(models.Model):
>> > user = models.ForeignKey(user)
>> > caption = models.CharField(max_length=200)
>> > image = models.ImageField(upload_to=get_upload_file_name)
>> > using_image = models.BooleanField()
>> >
>> > But with this I can select all of them, and not only one.
>> >
>> > Lets take an example of profile picture. A user can have many images,
>> but he can only select one as a profile picture. So, that if he selects
>> one, the other will be un-select itself.
>> > Hope everybody understood what I mean. Please ask me if didn't
>> understood. Also please correct me if my model is not correct. Thank you!
>> >
>>
>> I recently needed a similar thing (one item out of a table being _the_
>> thing) and decided that host table was the wrong place to store it. It
>> needs to be in the other table, in this case, your user table should have a
>> field that is the key of the profile picture.
>>
>>
>  --
> 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/6674AFD3-6F4F-4434-8903-B3B1CF43B03B%40gmail.com
> .
>
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
Rafael E. Ferrero

-- 
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/CAJJc_8UBKnc5DhncZiwSO7RNkFU23_2_zZiGrPSFqYr38mOLBw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Tutorials

2013-11-04 Thread Pepsodent Cola
Hi Jasvir,

Now your website looks more 2010 than 1990.  It looks fresh and is more
pleasant for the eyes for lengthy reading compared to your first website.
I might actually learn a few tricks or two when you have completed the
tutorials in the future.

The only thing I'm missing now is some sort of breadcrumb navigation that
tells me where I am and how much more I have to read for each chapter.
http://www.smashingmagazine.com/2009/03/17/breadcrumbs-in-web-design-examples-and-best-practices-2/

Official Django tutorials solves that by always having a sidebar menu, and
crazy long tutorials that fit into one Chapter page, then they have Next
and Prev buttons at the bottom saying "Next - Writing your first Django
app, Part 2".  That way I can keep track of my reading progress easier.
 But I wouldn't say that official Django tutorials is the perfect example
to copy when it comes to breadcrumb techniques.  But it semi-works for me,
at least I'm not totally lost but the navigation experience could be even
better.
https://docs.djangoproject.com/en/dev/intro/tutorial01/

You just need to find what solutions are readily available for your blog
engine which is Wordpress I guess and pick what suits your tutorial
structure and taste the best.







On Mon, Nov 4, 2013 at 11:28 AM, Jasvir Singh wrote:

> On Sat, Oct 26, 2013 at 6:35 PM, Jasvir Singh 
> wrote:
> > Here is link of my tutorials
> > http://goo.gl/3jPaf7
>
> Now these tutorials are shifted to my personal domain.
> http://www.jsgrewal.com/tutorials/django/
>
> @all, critical reviews are needed.
>
> --
>
> Jasvir Singh Grewal
> Blog:http://jasvirsinghgrewal91.wordpress.com/
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/DhMrcyK_XLY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAN_O85vDtM9rxyR896Ndc7dxBiwaCaT-CubOn0bR8tDUPfy3YA%40mail.gmail.com
> .
> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOWMwCzsxeo_b9gxfzn11MrCegKZVL0C-U7%3DxyGDqEg-ezMnOA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Tutorials

2013-11-04 Thread Jasvir Singh
On Mon, Nov 4, 2013 at 5:33 PM, Pepsodent Cola  wrote:

Hello Pepsodent.

> Now your website looks more 2010 than 1990.  It looks fresh and is more
> pleasant for the eyes for lengthy reading compared to your first website.

Thanks for your appreciation. :)

> The only thing I'm missing now is some sort of breadcrumb navigation that

> engine which is Wordpress I guess and pick what suits your tutorial
> structure and taste the best.

Thanks for your suggestion.
It's done. Now you can see there "you are here:". :)


-- 

Jasvir Singh Grewal
Blog:http://jasvirsinghgrewal91.wordpress.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To 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/CAN_O85tvekT5XoGOz6GtOSE2sRO4q0q4TK8f9XZH5q2uMbMUUw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re:

2013-11-04 Thread Tom Evans
On Sun, Nov 3, 2013 at 8:23 PM, Aamu Padi  wrote:
> How to make a model with a yes/no field, if yes that particular object
> (image) will be used as the background, and no other image will be selected.
>
> I have come with this model:
>
> class BackgroundImage(models.Model):
> user = models.ForeignKey(user)
> caption = models.CharField(max_length=200)
> image = models.ImageField(upload_to=get_upload_file_name)
> using_image = models.BooleanField()
>
> But with this I can select all of them, and not only one.
>
> Lets take an example of profile picture. A user can have many images, but he
> can only select one as a profile picture. So, that if he selects one, the
> other will be un-select itself.
> Hope everybody understood what I mean. Please ask me if didn't understood.
> Also please correct me if my model is not correct. Thank you!
>

User can have many images, but only one profile image:

class User:
  profile_image = ForeignKey('BackgroundImage', blank=True, null=True)
  # other fields

class BackgroundImage:
  owner = ForeignKey('User')
  # other fields

# get a profile pic
image_url = user.profile_pic and user.profile_pic.image.url or ''

# set a new profile pic
image = BackgroundImage()
user.profile_pic = image
user.save()

User can have many images, but only one profile image, without
modifying user model

class User:
  # other fields

class BackgroundImage:
  owner = ForeignKey('User')
  # other fields

class UserBackgroundImage:
  user = OneToOneField('User')
  profile_picture = ForeignKey('BackgroundImage')

# get a profile pic
image_url = user.userbackgroundimage and
user.backgroundimage.profile_picture.image.url or ''

# set a new profile pic
image = BackgroundImage()
user_image, created =
UserBackgroundImage.objects.get_or_create(user=user,
defaults={'profile_picture': image})
if not created:
  user_image.profile_picture = image
  user_image.save()

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1%2Bng1g2OtAtsTb43V-JFbetP5WVtvUO_8PWUzjAFPs%3DCQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Model to select only 1 object from multiple objects

2013-11-04 Thread Ruturaj Dhekane
Your model can work. But I think the model there is an alternate way to
create this model.

The way I might design this is have a profile model
Profile = name, birth date, location, favorite books, friends,
ProfilePicture (foreignKey)

ProfilePicture = image, caption
So now, you can have multiple profile pictures and the profile will point
to that profile picture which needs to be shown. Hope this helps.

To do it the way you are doing - you need to make sure that first all
User=X have set using_image=false. Then set the particular used
using_image=true. Then you can retrieve the unique photo for every user by
filtering on using_image = true This needs to be done in code rather than
in model.


On Mon, Nov 4, 2013 at 1:57 AM, Aamu Padi  wrote:

> How to make a model with a yes/no field, if yes that particular object
> (image) will be used as the background, and no other image will be
> selected.
>
> I have come with this model:
>
> class BackgroundImage(models.Model):
> user = models.ForeignKey(user)
> caption = models.CharField(max_length=
> 200)
> image = models.ImageField(upload_to=get_upload_file_name)
> using_image = models.BooleanField()
>
> But with this I can select all of them, and not only one.
>
> Lets take an example of profile picture. A user can have many images, but
> he can only select one as a profile picture. So, that if he selects one,
> the other will be un-select itself.
> Hope everybody understood what I mean. Please ask me if didn't understood.
> Also please correct me if my model is not correct. 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAHSNPWtW89SBNRnCh_EO6Uj1hTPhixsxSRwq%3DhHmuGzdTJfWAg%40mail.gmail.com
> .
> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEGxL4mu-%3DNkLMFz96m5tVr2%3DAggDh470%3DnRp7dKqWEgUvTQgQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Tutorials

2013-11-04 Thread Mario Osorio
Incredible!

Thank you very much for your effort. This is looks incredibly better than 
before.

Now, and  I don't mean to be picky.

Remember I'm a noob. I do however, have a lot of experience in failing when 
following tutorials.

I understand the tutorials are on django, and you've made a very nice job 
at keeping the sections small, clear, concise and to the point, but I  
think the use of virtualenv should be PUSHED into the minds of those noobs 
like me wanting to work with django. 

I also understand virtualenv is just desirable or recommended, but if you: 
1) are just learning the basics and/or 2) want to succeed deploying; 
virtualenv is a must, if not mandatory.

I've seen this omission in other tutorials and I don't mean each tutorial 
to make a whole chapter on virtualenv; but at least a few words describing 
what it is and why is it important are in order.

just my two cents ...

In any case; congrats, great job!!

-- 
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/1ddb4840-abdf-499b-bfaf-a92623ab3d0f%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


python.exe manage.py evolve --sql

2013-11-04 Thread fabricio

The following are the changes that could not be resolved:
In model cadastro.Codtributario_itens:
Field 'sai_subsmva' has been added
Field 'sai_uf' has been deleted
CommandError: Your models contain changes that Django Evolution cannot 
resolve automatically.

-- 
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/d51c873c-4ecf-4045-a1fb-9965815a82f2%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Custom User model admin log always adds Changed password record

2013-11-04 Thread John
I noticed if I comment out the line password = ReadOnlyPasswordHashField() 
in admin.py that I no longer run into this issue when saving, but then the 
field becomes editable and shows the hash.

# appname/models.py
from django.db import models

from django.contrib.auth.models import (
BaseUserManager, AbstractBaseUser, PermissionsMixin)


class UPDUserManager(BaseUserManager):

def create_user(self, email, first_name, last_name, password=None):
"""Create and save a user with the given email, first name,
last name and password.
"""
if not email:
raise ValueError("Users must have an email address.")

if not first_name:
raise ValueError("Users must have a first name.")

if not last_name:
raise ValueError("Users must have a last name.")

user = self.model(email=UPDUserManager.normalize_email(email),
  first_name=first_name,
  last_name=last_name,)

user.set_password(password)
user.save(using=self._db)
return user

def create_superuser(self, email, first_name, last_name, password):
"""Create and save a superuser with the given email, first name,
last name and password.
"""
user = self.create_user(email, first_name=first_name,
last_name=last_name, password=password)
user.is_staff = True
user.is_superuser = True
user.save(using=self._db)
return user


class UPDUser(AbstractBaseUser, PermissionsMixin):

"""Inherit from both the AbstractBaseUser and PermissionsMixin."""

email = models.EmailField(verbose_name='email address', max_length=255,
  unique=True, db_index=True)
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=False)

objects = UPDUserManager()

USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['first_name', 'last_name']

def get_full_name(self):
"""Return the first_name and last_name."""
return "%s %s" % (self.first_name, self.last_name)

def get_short_name(self):
"""Return the first_name."""
return self.first_name

def __unicode__(self):
"""Return the user's email address."""
return self.email


-- 
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/8ca0a1e2-ff36-4b30-98ad-985a8dfb9050%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Model to select only 1 object from multiple objects

2013-11-04 Thread Aamu Padi
Thank you. I hope I can walk through now. :)


On Mon, Nov 4, 2013 at 7:43 PM, Ruturaj Dhekane  wrote:

> Your model can work. But I think the model there is an alternate way to
> create this model.
>
> The way I might design this is have a profile model
> Profile = name, birth date, location, favorite books, friends,
> ProfilePicture (foreignKey)
>
> ProfilePicture = image, caption
> So now, you can have multiple profile pictures and the profile will point
> to that profile picture which needs to be shown. Hope this helps.
>
> To do it the way you are doing - you need to make sure that first all
> User=X have set using_image=false. Then set the particular used
> using_image=true. Then you can retrieve the unique photo for every user by
> filtering on using_image = true This needs to be done in code rather than
> in model.
>
>
> On Mon, Nov 4, 2013 at 1:57 AM, Aamu Padi  wrote:
>
>> How to make a model with a yes/no field, if yes that particular object
>> (image) will be used as the background, and no other image will be
>> selected.
>>
>> I have come with this model:
>>
>> class BackgroundImage(models.Model):
>> user = models.ForeignKey(user)
>> caption = models.CharField(max_length=
>> 200)
>> image = models.ImageField(upload_to=get_upload_file_name)
>> using_image = models.BooleanField()
>>
>> But with this I can select all of them, and not only one.
>>
>> Lets take an example of profile picture. A user can have many images, but
>> he can only select one as a profile picture. So, that if he selects one,
>> the other will be un-select itself.
>> Hope everybody understood what I mean. Please ask me if didn't
>> understood. Also please correct me if my model is not correct. 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.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAHSNPWtW89SBNRnCh_EO6Uj1hTPhixsxSRwq%3DhHmuGzdTJfWAg%40mail.gmail.com
>> .
>> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAEGxL4mu-%3DNkLMFz96m5tVr2%3DAggDh470%3DnRp7dKqWEgUvTQgQ%40mail.gmail.com
> .
> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHSNPWu3sGB%3Dexcqy_fSOpOKd%2B-WBeeoU3mm_v9b1j7iuGhMsg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


How to add objects from one class to another

2013-11-04 Thread Aamu Padi
This is my models.py:

class Image(models.Model):
user = models.ForeignKey(User)
caption = models.CharField(max_length=300)
image = models.ImageField(upload_to=get_upload_file_name)
pub_date = models.DateTimeField(default=datetime.now)

class Meta:
ordering = ['-pub_date']
verbose_name_plural = ('Images')

def __unicode__(self):
return "%s - %s" % (self.caption, self.user.username)


class ProfilePic(Image):
pass



class BackgroundPic(Image):
pass


class Album(models.Model):
name = models.CharField(max_length=150)

def __unicode__(self):
return self.name


class Photo(Image):
album = models.ForeignKey(Album, default=3)

And this is another:

class UserProfile(models.Model):
user = models.OneToOneField(User)
permanent_address = models.TextField()
temporary_address = models.TextField()
profile_pic = models.ForeignKey(ProfilePic)
background_pic = models.ForeignKey(BackgroundPic)

def __unicode__(self):
return self.user.username

I can access the Parent class with its User object.

>>>m = User.objects.get(username='mika')
>>>m.image_set.all()
>>>[, , ]


But I can't access its child class with the User. I tried:

>>>m.Image.profilepic_set.all()
and

>>>m.image_set.profilpic.all()

and this

>>>m.profilepic_set.all()
AttributeError:'User' object has no attribute 'profilepic_set'

But all gave me errors!  How do I access the child classes, so that I can
add images from one class to another. Like copy one image from Photo to
ProfilePic, or from ProfilePic to BackgroundPic and so. Or simply, how to
add images for particular User in specific classes?

Please guide me to achieve the above mentioned. Will be much appreciated.
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHSNPWsBg1sgWTQF%3D5zzKXiz2-yt8twVDnv8xP1bM2tJeZF4qw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: How to add objects from one class to another

2013-11-04 Thread Aamu Padi
What I want is that, each user will have a set of `profile pictures`,
`background images` and other set of `photos uploaded`. These images will
be kept separately in the templates. And if the user wants, he can easily
use (copy) the other set of photos uploaded or images from the background
image set, as the profile picture, and that image will be added to `profile
picture set`. Or if he wants, he can use an image from `profile picture
set` or from the other `uploaded photos` as the `background image` and
similarly that image used from other class will be copied to `background
image set`.


On Tue, Nov 5, 2013 at 4:03 AM, Aamu Padi  wrote:

> This is my models.py:
>
> class Image(models.Model):
> user = models.ForeignKey(User)
> caption = models.CharField(max_length=300)
> image = models.ImageField(upload_to=get_upload_file_name)
> pub_date = models.DateTimeField(default=datetime.now)
>
> class Meta:
> ordering = ['-pub_date']
> verbose_name_plural = ('Images')
>
> def __unicode__(self):
> return "%s - %s" % (self.caption, self.user.username)
>
>
> class ProfilePic(Image):
> pass
>
>
>
> class BackgroundPic(Image):
> pass
>
>
> class Album(models.Model):
> name = models.CharField(max_length=150)
>
> def __unicode__(self):
> return self.name
>
>
> class Photo(Image):
> album = models.ForeignKey(Album, default=3)
>
> And this is another:
>
> class UserProfile(models.Model):
> user = models.OneToOneField(User)
> permanent_address = models.TextField()
> temporary_address = models.TextField()
> profile_pic = models.ForeignKey(ProfilePic)
> background_pic = models.ForeignKey(BackgroundPic)
>
> def __unicode__(self):
> return self.user.username
>
> I can access the Parent class with its User object.
>
> >>>m = User.objects.get(username='mika')
> >>>m.image_set.all()
> >>>[, ,  mika_bf - mika>]
>
>
> But I can't access its child class with the User. I tried:
>
> >>>m.Image.profilepic_set.all()
> and
>
> >>>m.image_set.profilpic.all()
>
> and this
>
> >>>m.profilepic_set.all()
> AttributeError:'User' object has no attribute 'profilepic_set'
>
> But all gave me errors!  How do I access the child classes, so that I can
> add images from one class to another. Like copy one image from Photo to
> ProfilePic, or from ProfilePic to BackgroundPic and so. Or simply, how to
> add images for particular User in specific classes?
>
> Please guide me to achieve the above mentioned. Will be much appreciated.
> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHSNPWuofMKV1PLdcPJ8FTk4BsHiBAC2VrOQ4xZw4MNUd1U4uw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: How to add objects from one class to another

2013-11-04 Thread Gonzalo Delgado
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

El 04/11/13 19:33, Aamu Padi escribió:
> This is my models.py:
> 
> class Image(models.Model): user = models.ForeignKey(User) caption =
> models.CharField(max_length=300) image =
> models.ImageField(upload_to=get_upload_file_name) pub_date =
> models.DateTimeField(default=datetime.now)
> 
> class Meta: ordering = ['-pub_date'] verbose_name_plural =
> ('Images')
> 
> def __unicode__(self): return "%s - %s" % (self.caption,
> self.user.username)
> 
> 
> class ProfilePic(Image): pass
> 
> 
> 
> class BackgroundPic(Image): pass
> 
> 
> class Album(models.Model): name = models.CharField(max_length=150)
> 
> def __unicode__(self): return self.name
> 
> 
> class Photo(Image): album = models.ForeignKey(Album, default=3)
> 
> And this is another:
> 
> class UserProfile(models.Model): user = models.OneToOneField(User) 
> permanent_address = models.TextField() temporary_address =
> models.TextField() profile_pic = models.ForeignKey(ProfilePic) 
> background_pic = models.ForeignKey(BackgroundPic)
> 
> def __unicode__(self): return self.user.username
> 
> I can access the Parent class with its User object.
> 
 m = User.objects.get(username='mika') m.image_set.all() 
 [, ,
  mika_bf - mika>]
> 
> 
> But I can't access its child class with the User. I tried:
> 
 m.Image.profilepic_set.all()
> and
> 
 m.image_set.profilpic.all()
> 
> and this
> 
 m.profilepic_set.all()
> AttributeError:'User' object has no attribute 'profilepic_set'
> 
> But all gave me errors!  How do I access the child classes, so that
> I can add images from one class to another. Like copy one image
> from Photo to ProfilePic, or from ProfilePic to BackgroundPic and
> so. Or simply, how to add images for particular User in specific
> classes?

I don't think Django supports that kind of queries. You can try
django-polymorphic for something very close to what you want:
https://github.com/chrisglass/django_polymorphic

My recommendation, though, would be to not use inheritance that way
and simply add an "image_type" field to your Image model and filter
that instead:

 class Image(models.Model):
 user = models.ForeignKey(User)
 caption = models.CharField(max_length=300)
 image = models.ImageField(upload_to=get_upload_file_name)
 pub_date = models.DateTimeField(default=datetime.now)
 image_type = models.CharField(
 max_length=20, choices=(('background', 'Background'),
 ('profile', 'Profile')))

and do:
m.image_set.filter(image_type='background')
or:
m.image_set.filter(image_type='profile')


Another possibility would be to make Image an abstract model. Your
references to profilepic_set and backgroundpic_set will work, but you
won't be able to use the Image model to store data in the database.


- -- 
Gonzalo Delgado
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.15 (Darwin)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iF4EAREIAAYFAlJ4QE8ACgkQzbfdFL5JoUlCDAEAkyrstji355TouLYZDjXmax8x
mFnN0nQ2lDbo0lUNiBsA/27hAQNhX74p1Wb3O1e3qjkK23nj6NCL09GL167Knl0h
=5oiE
-END PGP SIGNATURE-

-- 
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/5278404F.8080805%40gonzalodelgado.com.ar.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Complex query reduction

2013-11-04 Thread Apostolos Bessas
On Sat, Nov 2, 2013 at 4:50 PM, Daniele Procida  wrote:
>
> But, the real killer is the combination of ordering (in the queryset or on 
> the model, it doesn't matter) with the distinct() - as soon as one is removed 
> from the equation, the execution time drops to around 250ms.
>
> That's for 55000 BibliographicRecords created by that last operation (before 
> distinct() is applied; distinct() reduces them to 28000).


Do you happen to use PostgreSQL? This could be a case of a
"non-optimal" configuration, that makes PostgreSQL use the disk to do
the sorting. Take a look at
http://www.postgresql.org/docs/current/static/runtime-config-resource.html#GUC-WORK-MEM.

Apostolis

-- 
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/CAEa3b%2BoCFp3oPwtcR-uyoERW3YwHR4aXLubp7WUpa%2BHtYNhvmw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.