How do I redirect a logged in customer to https page?

2013-02-11 Thread Alagappan
Hi,

In my website, I have a few http pages and a few https pages.

The session cookie has been made secure=True and once a customer logs in to
the site, we keep all pages as https.

But if the customer manually changes the URL to http, Django's
user.is_authenticated method returns False and hence is shown some content
that is to be shown for an anonymous user.

Is there a way I can redirect logged in customers to https pages even if
he/she manually changes the URL. This can either be at the project level or
in server level.

I am using Apache/mod_wsgi to run my website.

I hope I have worded my query in a clear manner. Please let me know if I
need to provide further details.

Thanks,
Alagappan



-- 
Thanks & Regards,
Alagappan Ramu
+91 9840 143 620

http://about.me/alagappanr

NIT Trichy  | Global Analytics India Pvt
Ltd

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




Updated Django by Example tutorials

2013-02-11 Thread Rainy
Hi, I've started updating Django by Example tutorials for django version 
1.5 and using class-based views.
I have posted 3 tutorials so far; 3 more will be added soon:

http://lightbird.net/dbe2/

I hope these will prove to be useful.. please let me know of any issues / 
ways to improve the guide.

 - rainy

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




use app_label

2013-02-11 Thread carlos
Hi I have an app called myapp within my models eg

class Foo(models):
fields1 = models(blabla)
fields2 = models(blabla)

class Meta:
verbose_name = "Foo model"
app_label = 'candy'
db_table = 'myapp_foo'

class Bar(models):
   fields1 = models(blabla)
fields2 = models(blabla)

class Meta:
verbose_name = "Bar model"
app_label = 'chocolate'
db_table = 'myapp_bar'

now I separate them for the admin i use app_label that this show separately
and it works but as super user when i create group
but do not see it does not appear

how I can fix this?

The only code I use is the one above

thank!!

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




One-to-many relationships in submission forms

2013-02-11 Thread Skip Montanaro
I'm trying to learn Django by implementing a bicycle serial number 
database.  A bike is a specific model from a given manufacturer.  Each 
frame of a given model can have multiple serial numbers at different 
locations on the frame.  These relationships are easily captured in this 
simplified model definition:

class Manufacturer(models.Model):
name = models.CharField(max_length=64)

class Model(models.Model):
manufacturer = models.ForeignKey(Manufacturer)
name = models.CharField(max_length=64)

class Frame(models.Model):
model = models.ForeignKey(Model)
year = models.IntegerField(blank=True, null=True)

class SerialNumber(models.Model):
number = models.CharField(max_length=64)
location = models.CharField(max_length=4,
choices=LOCATION_CHOICES) # 
LOCATION_CHOICES is elided here...
frame = models.ForeignKey(Frame)

Now, this application is essentially a means to populate a database, so 
I've been tempted to just use the admin interface and dole out logins for 
people I trust.  That has two problems.  One, I will eventually encounter 
someone who's not trustworthy.  Two, I won't learn much about creating 
forms.

So, I'd like to create a form which allows users to add a frame to the 
database with the opportunity to submit multiple serial numbers at one go. 
 It's not clear to me what I should use.  I sort of think inline formsets 
are candidates, but have had precious little luck finding an explanation of 
what their object is, and even less luck finding a tutorial type example. 
 I did find an example here:

https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#inline-formsets

which looked promising, and I was able to adapt the BookFormSet and print 
its as_table() output (lots of interesting HTML), but I can't make it work 
in "real life".  I defined these SNFormSet and AddForm classes:

SNFormSet = inlineformset_factory(Frame, SerialNumber)

class AddForm(forms.Form):
man = 
forms.ModelChoiceField(queryset=Manufacturer.objects.order_by("name"),
 label="Manfacturer")
mod = forms.CharField(max_length=100, label="Model")
snset = SNFormSet(instance=Frame())

When I display the form, I see widgets for the manufacturer and model, but 
nothing related to the SNFormSet. I must be missing some connection between 
the SNFormSet instance and the AddForm, but It's not clear what.

Any suggestions?

Thx,

Skip Montanaro

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




Re: Any good books for learning django?

2013-02-11 Thread vijay shanker
thanks, i bought it :)

On Monday, February 11, 2013 7:37:28 PM UTC+5:30, frocco wrote:
>
> That's good to know, hopefully the person asked for a free copy will head 
> over to there.
>
> On Monday, February 11, 2013 8:52:52 AM UTC-5, W. wrote:
>>
>> Do not pirate. 
>> However. If you checked their webpage https://django.2scoops.org/ , you 
>> would see. 
>>
>> Can't Afford the Book? 
>>>
>>> If you're struggling with finances and can't afford it, let us know and 
>>> we'd be happy to send you a free copy. Drop us a note at  and 
>>> we'll get it to you within 72 hours.
>>>
>> Best regards, 
>>
>> W. 
>>
>> Dne pátek, 8. února 2013 11:13:11 UTC+1 vijay shanker napsal(a):
>>>
>>> do u have the pdf ?
>>> will u share it at some place (or please mail it to me deon...@gmail.com
>>> )
>>>
>>> On Thursday, February 7, 2013 11:40:01 PM UTC+5:30, Mayukh Mukherjee 
>>> wrote:

 I'd recommend two scoops of django.
 It's a little more intermediate level but it's a gem.

 Sent from my iPhone

 On Feb 7, 2013, at 12:49, frocco  wrote:

 Hello,
 Most of what I find are dated, 2008,2009.
 Are these still good for learning django 1.4?

 Which books do you recommend?

 Thanks

 -- 
 You received this message because you are subscribed to the Google 
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to django-users...@googlegroups.com.
 To post to this group, send email to django...@googlegroups.com.
 Visit this group at 
 http://groups.google.com/group/django-users?hl=en.
 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Any good books for learning django?

2013-02-11 Thread vijay shanker
yes u right .. my bad

On Friday, February 8, 2013 6:28:20 PM UTC+5:30, Tom Evans wrote:
>
> On Fri, Feb 8, 2013 at 10:13 AM, vijay shanker 
>  
> wrote: 
> > do u have the pdf ? 
> > will u share it at some place (or please mail it to me 
> > deon...@gmail.com) 
>
>
> Please don't use this list to arrange or ask others to pirate books. 
> The author of any django book almost certainly is a subscriber, you 
> are stealing his/her work from under their nose. 
>
> Please don't pirate technical books anyway. If everyone pirated 
> technical books, there would be no incentive to write new technical 
> books, and everyone loses out. 
>
> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How do I get the current user in a model?

2013-02-11 Thread frocco
Thanks Brad,

I got it working.

@register.filter(name='price')
def price(model, user):
u = UserGroup.objects.get(user_id=user.id)
level = u.price_level
if level == 'B':
return model.price_b
if level == 'C':
return model.price_c
if level == 'D':
return model.price_d
if level == 'E':
return model.price_e
return model.price_a

{{ row|price:request.user }}

On Monday, February 11, 2013 10:54:53 AM UTC-5, Brad Pitcher wrote:
>
> Sounds like you are maybe calling a user method from a template? You 
> will probably want to create a custom tag or filter: 
> https://docs.djangoproject.com/en/1.4/howto/custom-template-tags/ 
>
> A filter would look like this: 
> {{ my_model_item|price:request.user }} 
>
> And the filter itself something like this: 
>
> def price(my_model_item, user): 
> """Returns the price for the user""" 
> # Logic to evaluate the price could be here on in a 
> # model method, but if it's in the model method you 
> # will need to pass the user as a parameter to that 
> # method. 
> return evaluated_price 
>
> On Mon, 2013-02-11 at 07:05 -0800, frocco wrote: 
> > What I am trying to do, is I have four price fields in my model and 
> > need to return just one based on current user logged in. 
> > 
> > 
> > price_a 
> > price_b 
> > price_c 
> > price_d 
> > 
> > 
> > I want to always return a field named price, based on one of those 
> > fields. 
> > 
> > On Monday, February 11, 2013 9:51:47 AM UTC-5, frocco wrote: 
> > Ok, but is request available in models.py? 
> > 
> > 
> > On Monday, February 11, 2013 9:49:47 AM UTC-5, sandy wrote: 
> > On Mon, Feb 11, 2013 at 7:42 PM, frocco 
> >  wrote: 
> > > Hello, 
> > > 
> > > I have some logic I want to put in a model, but it 
> > requires know the current 
> > > user logged in. 
> > > Is there a way to get this? 
> > > 
> > This gets the current logged in user : 
> > 
> > current_user = request.user 
> > 
> > -- 
> > Sandeep Kaur 
> > E-Mail: mkaur...@gmail.com 
> > Blog: sandymadaan.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...@googlegroups.com . 
> > To post to this group, send email to 
> > django...@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. 
> >   
> >   
>
>
>

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




Re: How do I get the current user in a model?

2013-02-11 Thread Bill Freeman
On Mon, Feb 11, 2013 at 10:05 AM, frocco  wrote:

> What I am trying to do, is I have four price fields in my model and need
> to return just one based on current user logged in.
>
> price_a
> price_b
> price_c
> price_d
>
> I want to always return a field named price, based on one of those fields.
>
>
> On Monday, February 11, 2013 9:51:47 AM UTC-5, frocco wrote:
>>
>> Ok, but is request available in models.py?
>>
>>
>> On Monday, February 11, 2013 9:49:47 AM UTC-5, sandy wrote:
>>>
>>> On Mon, Feb 11, 2013 at 7:42 PM, frocco  wrote:
>>> > Hello,
>>> >
>>> > I have some logic I want to put in a model, but it requires know the
>>> current
>>> > user logged in.
>>> > Is there a way to get this?
>>> >
>>> This gets the current logged in user :
>>>
>>> current_user = request.user
>>>
>>> --
>>> Sandeep Kaur
>>> E-Mail: mkaur...@gmail.com
>>> Blog: sandymadaan.wordpress.com
>>>
>>
>
> There is only such a thing as a current user during a request.  The view
knows the request.  The request can be known in template context if the
view allows it (e.g.; uses a request context).  Any model method that
depends on information from the request (like request.user) needs to be
passed that information as an argument).  While you can't pass an argument
to a method being called using vanilla template syntax, you could write a
custom template tag, allowing, for example {% get_user_specific_price
model_instance %} .  (Tags have access to the context, so you need not pass
it explicitly.  Your view would still need to add request or request.user
to the context, unless you use a suitable template context processor to do
so.)

Bill

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




Re: Overall Design Question

2013-02-11 Thread Gabriel Abdalla
Hi Alex,

I'm still new to Django and Python, but I have experience in other
frameworks. Here is my opinion regarding your three points:

*(1) An app for each role.* I think the approach of having one app for each
role is the worst thing to do. In this case, you would have too much
duplicated code and the maintenance would be difficult.

*(2) Some logic in templates.* If you have it in templates, you would be
putting logic in the Template tier of your application, which, in my point
of view, is architecturally wrong. You should separate Model, Template and
View (MTV).

*(3) Any other.* I believe the best approach is to define permissions for
each user role. I don't know how to implement it in a Django application
yet, but I'm quite sure this is the right thing to do. From the documents
I've read, it should be implemented in the View tier.

Please correct me if I'm wrong.

Regards,

Gabriel Abdalla


On 11 February 2013 13:30, Bill Freeman  wrote:

>
>
> On Mon, Feb 11, 2013 at 7:13 AM, Ajinkya Gadewar <
> ajinkya.gade...@ishareitall.com> wrote:
>
>> Hi Alex,
>>
>> I already have a education system developed. We run a software company in
>> India. Let me know if you need more details on it.
>>
>> Regards,
>> Ajinkya Gadewar
>>
>> Sent from my iPhone
>>
>> On 11-Feb-2013, at 2:17 PM, "alexandre...@gmail.com" <
>> alexandre...@gmail.com> wrote:
>>
>> Hi
>> I'm starting a big app on Django for Shool management, to replace a Win32
>> app.
>>
>> I've roles like teachers, students, admin stuff, ... that have diferent
>> access.
>> How should it be developded?
>>
>> 1- an app for each role?
>> 2- some logic in templates?
>> 3- any other
>>
>> what is the correct aporach to get big and simple.
>>
>> Regards
>> Alex
>>
>>  --
>> 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.
>>
>>
>>
>>
>> An app for each role would seem to lead to a lot of code duplication.  I
> think that permissions are best implemented at the view level (and
> templates can be taken to be part of the view).  While you should restrict
> some views entirely by role, you will also want some template code, so that
> links to those views won't display for those whose role can't access them
> (though you could also hide unusable links with css and a roll based class
> on the body element).  There may also be views that should be read only for
> some roles and a form for others (though I prefer the separate "edit this
> stuff" view approach).  Consider using the django permissions and group
> system for roles.
>
> Bill
>
> --
> 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.
>
>
>

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




Re: How do I get the current user in a model?

2013-02-11 Thread Brad
Sounds like you are maybe calling a user method from a template? You
will probably want to create a custom tag or filter:
https://docs.djangoproject.com/en/1.4/howto/custom-template-tags/

A filter would look like this:
{{ my_model_item|price:request.user }}

And the filter itself something like this:

def price(my_model_item, user):
"""Returns the price for the user"""
# Logic to evaluate the price could be here on in a
# model method, but if it's in the model method you
# will need to pass the user as a parameter to that
# method.
return evaluated_price

On Mon, 2013-02-11 at 07:05 -0800, frocco wrote:
> What I am trying to do, is I have four price fields in my model and
> need to return just one based on current user logged in.
> 
> 
> price_a
> price_b
> price_c
> price_d
> 
> 
> I want to always return a field named price, based on one of those
> fields.
> 
> On Monday, February 11, 2013 9:51:47 AM UTC-5, frocco wrote:
> Ok, but is request available in models.py?
> 
> 
> On Monday, February 11, 2013 9:49:47 AM UTC-5, sandy wrote:
> On Mon, Feb 11, 2013 at 7:42 PM, frocco
>  wrote: 
> > Hello, 
> > 
> > I have some logic I want to put in a model, but it
> requires know the current 
> > user logged in. 
> > Is there a way to get this? 
> > 
> This gets the current logged in user : 
> 
> current_user = request.user 
> 
> -- 
> Sandeep Kaur 
> E-Mail: mkaur...@gmail.com 
> Blog: sandymadaan.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?hl=en.
> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Overall Design Question

2013-02-11 Thread Bill Freeman
On Mon, Feb 11, 2013 at 7:13 AM, Ajinkya Gadewar <
ajinkya.gade...@ishareitall.com> wrote:

> Hi Alex,
>
> I already have a education system developed. We run a software company in
> India. Let me know if you need more details on it.
>
> Regards,
> Ajinkya Gadewar
>
> Sent from my iPhone
>
> On 11-Feb-2013, at 2:17 PM, "alexandre...@gmail.com" <
> alexandre...@gmail.com> wrote:
>
> Hi
> I'm starting a big app on Django for Shool management, to replace a Win32
> app.
>
> I've roles like teachers, students, admin stuff, ... that have diferent
> access.
> How should it be developded?
>
> 1- an app for each role?
> 2- some logic in templates?
> 3- any other
>
> what is the correct aporach to get big and simple.
>
> Regards
> Alex
>
>  --
> 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.
>
>
>
>
> An app for each role would seem to lead to a lot of code duplication.  I
think that permissions are best implemented at the view level (and
templates can be taken to be part of the view).  While you should restrict
some views entirely by role, you will also want some template code, so that
links to those views won't display for those whose role can't access them
(though you could also hide unusable links with css and a roll based class
on the body element).  There may also be views that should be read only for
some roles and a form for others (though I prefer the separate "edit this
stuff" view approach).  Consider using the django permissions and group
system for roles.

Bill

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




Re: How do I get the current user in a model?

2013-02-11 Thread frocco
What I am trying to do, is I have four price fields in my model and need to 
return just one based on current user logged in.

price_a
price_b
price_c
price_d

I want to always return a field named price, based on one of those fields.

On Monday, February 11, 2013 9:51:47 AM UTC-5, frocco wrote:
>
> Ok, but is request available in models.py?
>
>
> On Monday, February 11, 2013 9:49:47 AM UTC-5, sandy wrote:
>>
>> On Mon, Feb 11, 2013 at 7:42 PM, frocco  wrote: 
>> > Hello, 
>> > 
>> > I have some logic I want to put in a model, but it requires know the 
>> current 
>> > user logged in. 
>> > Is there a way to get this? 
>> > 
>> This gets the current logged in user : 
>>
>> current_user = request.user 
>>
>> -- 
>> Sandeep Kaur 
>> E-Mail: mkaur...@gmail.com 
>> Blog: sandymadaan.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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Question on django scrapy integration

2013-02-11 Thread kl4us
is possible to Poll.objects.get(pk=1) into scrapy?

Il giorno lunedì 11 febbraio 2013 14:48:51 UTC+1, kl4us ha scritto:
>
> Hi all,
> i have a question on scrapy -> django integration.
>
> i have this models on django:
>
> from django.db import models
> from django.utils import timezone
> import datetime
> class Job(models.Model):
> title = models.CharField(max_length=100)
> description = models.TextField(max_length=500)
> url = models.URLField()
> pub_date = models.DateTimeField('date published')
> rand_ord = models.FloatField(default=0)
> def __unicode__(self):
> return self.title
> def was_published_recently(self):
> return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
> was_published_recently.admin_order_field = 'pub_date'
> was_published_recently.boolean = True
> was_published_recently.short_description = 'Published recently?'
> class Attribute(models.Model):
> description = models.CharField(max_length=50)
> def __unicode__(self):
> return self.description
> class JobAttribute(models.Model):
> attribute_id = models.ForeignKey(Attribute)
> job_id = models.ForeignKey(Job)
> value = models.CharField(max_length=50)
>
>
> and i'm going to write the pipeline.
>
> In scrapy i have items:
>
> from scrapy.contrib.djangoitem import DjangoItem
> from jobs.models import Job, JobAttribute, Attribute
>
> class JobItem(DjangoItem):
> django_model = Job
>
> class JobAttributeItem(DjangoItem):
> django_model = JobAttribute
>
> class AttributeItem(DjangoItem):
> django_model = Attribute
>
>
> in my spider i have:
>
> item = JobItem()
> item["url"] = response.url
> item["title"] = 'something'
> item['pub_date'] = 'something'
> item["description"] = 'something'
> item.save()
>
>
>
> Everythings work fine. But now i want to save JobAttributeItem too:
>
> item_jobattribute = JobAttributeItem()
> item_jobattribute['job_id'] = 'want a job object'
> item_jobattribute['attribute_id'] = 'what a attribute object'
> item_jobattribute['value'] = 'something'
> item_jobattribute.save()
>
>
> how can i do this?
> Thanks a lot
>

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




Re: IntegrityError when creating a brand new model instance

2013-02-11 Thread Bill Freeman
On Sun, Feb 10, 2013 at 10:50 AM, Some Developer
wrote:

> On 10/02/13 15:07, Bill Freeman wrote:
>
>> Did you previously have a field named 'title' in this model that was
>> marked unique, that you have since removed?  If so, the column may still
>> be in the database with a unique constraint.  Since it's no longer in
>> the model, some default may be being used when you save, and that's
>> obviously not unique.  Use suitable tools for your database (if
>> PostgreSQL, I suggest PGAdminIII) to examine the schema.  You may be
>> able to drop the column, or at least the constraint (back up the
>> database first).
>>
>> If there never was such a field, then the problem originates in another
>> model.  You still may be able to figure it out by inspecting the
>> database schema.  You can also temporarily set up to catch the Integrity
>> Error close to the origin, and call pdb.set_trace(), where you can
>> examine the query to see what models are involved.
>>
>> Bill
>>
>
> OK, I've just found something rather strange. If I just do a simple:
>
> tag = BlogTag(title=form.cleaned_**data['title'],
>
> description=form.cleaned_data[**'description'],
> num_articles=0)
>
> tag.save()
>
> I get an IntegrityError and the model fails to save. On the other hand if
> I do the following:
>
> try:
> tag = BlogTag(title=form.cleaned_**data['title'],
>
> description=form.cleaned_data[**'description'],
> num_articles=0)
>
> tag.save()
>
> except Exception:
> pass
>
> the model saves correctly (I've checked manually in the SQLite database)
> and there is no error shown at all (as expected since I have ignored the
> exception).
>
> Any idea why this is the case? If it truly were a database constraint
> violation I would have assumed that it would fail to save no matter what
> you did regarding Python exceptions.
>
> This feels like a bug in Django to me.
>
> Suggestions welcome.
>
>
I have to agree that catching exceptions doesn't clear IntegrityError.  But
that still doesn't tell us where the bug is.

Does this happen on the development server?  If so, then my suggestion is
to sprinkle in a pdb.set_trace() or two, poke around and/or single step
over a few things, then go around again and single step into the thing that
fails, and repeat until enlightened.

If it only happens on a production server, you're stuck with printing
stuff.  For instance, since your except only has a pass, we don't actually
know whether it was reached.  You can't in general, print to stdout.  I
believe that apache/mod_wsgi puts stuff sent to stderr in the apacvhe
longs.  Django's logging may  help.  I'm fond of writing a little function
that appends its text argument to a file of your choice.

Bill

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




Re: How do I get the current user in a model?

2013-02-11 Thread frocco
Ok, but is request available in models.py?


On Monday, February 11, 2013 9:49:47 AM UTC-5, sandy wrote:
>
> On Mon, Feb 11, 2013 at 7:42 PM, frocco  
> wrote: 
> > Hello, 
> > 
> > I have some logic I want to put in a model, but it requires know the 
> current 
> > user logged in. 
> > Is there a way to get this? 
> > 
> This gets the current logged in user : 
>
> current_user = request.user 
>
> -- 
> Sandeep Kaur 
> E-Mail: mkaur...@gmail.com  
> Blog: sandymadaan.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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How do I get the current user in a model?

2013-02-11 Thread Sandeep kaur
On Mon, Feb 11, 2013 at 7:42 PM, frocco  wrote:
> Hello,
>
> I have some logic I want to put in a model, but it requires know the current
> user logged in.
> Is there a way to get this?
>
This gets the current logged in user :

current_user = request.user

-- 
Sandeep Kaur
E-Mail: mkaurkha...@gmail.com
Blog: sandymadaan.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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




ContentType's model_class is NoneType

2013-02-11 Thread vijay shanker
Hi
I have few models in a app called shoppingcart.
I can find contenttypes associated with this model with this: 
>>>ct = ContentType.objects.filter(app_label='shoppingcart') 
>>>ct
[, , , 
]

but when i try ct[0].model_class() it returns the model class on shell but 
gives me a NoneType when i try to get all models as a tuple so that i can 
populate them as choices of field with this iterator MODELCHOICES  = [each 
for each in GetAllModels]
I have the required tables in database. (had once deleted all contenttypes 
for this app and synced db to recreate the table)
 
class GetAllModels(object):
def __init__(self,counter=0):
self.counter = counter
def __iter__(self):
return self
def next(self):
ct = 
list(ContentType.objects.filter(app_label__in=['shoppingcart','products','productoptions']))
if self.counter < len(ct):
mclass = ct[self.counter].model_class()
self.counter = self.counter +1
return ('.'.join([mclass.__module__,mclass.__name__]), 
mclass.__name__)
else:
raise StopIteration

Please enlighten me !

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




How do I get the current user in a model?

2013-02-11 Thread frocco
Hello,

I have some logic I want to put in a model, but it requires know the 
current user logged in.
Is there a way to get this?

The template would have to display the results of the field returned from 
the model.

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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Any good books for learning django?

2013-02-11 Thread frocco
That's good to know, hopefully the person asked for a free copy will head 
over to there.

On Monday, February 11, 2013 8:52:52 AM UTC-5, W. wrote:
>
> Do not pirate. 
> However. If you checked their webpage https://django.2scoops.org/ , you 
> would see. 
>
> Can't Afford the Book? 
>>
>> If you're struggling with finances and can't afford it, let us know and 
>> we'd be happy to send you a free copy. Drop us a note at  and 
>> we'll get it to you within 72 hours.
>>
> Best regards, 
>
> W. 
>
> Dne pátek, 8. února 2013 11:13:11 UTC+1 vijay shanker napsal(a):
>>
>> do u have the pdf ?
>> will u share it at some place (or please mail it to me deon...@gmail.com)
>>
>> On Thursday, February 7, 2013 11:40:01 PM UTC+5:30, Mayukh Mukherjee 
>> wrote:
>>>
>>> I'd recommend two scoops of django.
>>> It's a little more intermediate level but it's a gem.
>>>
>>> Sent from my iPhone
>>>
>>> On Feb 7, 2013, at 12:49, frocco  wrote:
>>>
>>> Hello,
>>> Most of what I find are dated, 2008,2009.
>>> Are these still good for learning django 1.4?
>>>
>>> Which books do you recommend?
>>>
>>> Thanks
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at 
>>> http://groups.google.com/group/django-users?hl=en.
>>> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Any good books for learning django?

2013-02-11 Thread W.
Do not pirate. 
However. If you checked their webpage https://django.2scoops.org/ , you 
would see. 

Can't Afford the Book? 
>
> If you're struggling with finances and can't afford it, let us know and 
> we'd be happy to send you a free copy. Drop us a note at  and 
> we'll get it to you within 72 hours.
>
Best regards, 

W. 

Dne pátek, 8. února 2013 11:13:11 UTC+1 vijay shanker napsal(a):
>
> do u have the pdf ?
> will u share it at some place (or please mail it to me 
> deon...@gmail.com
> )
>
> On Thursday, February 7, 2013 11:40:01 PM UTC+5:30, Mayukh Mukherjee wrote:
>>
>> I'd recommend two scoops of django.
>> It's a little more intermediate level but it's a gem.
>>
>> Sent from my iPhone
>>
>> On Feb 7, 2013, at 12:49, frocco  wrote:
>>
>> Hello,
>> Most of what I find are dated, 2008,2009.
>> Are these still good for learning django 1.4?
>>
>> Which books do you recommend?
>>
>> Thanks
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com.
>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Question on django scrapy integration

2013-02-11 Thread kl4us
Hi all,
i have a question on scrapy -> django integration.

i have this models on django:

from django.db import models
from django.utils import timezone
import datetime
class Job(models.Model):
title = models.CharField(max_length=100)
description = models.TextField(max_length=500)
url = models.URLField()
pub_date = models.DateTimeField('date published')
rand_ord = models.FloatField(default=0)
def __unicode__(self):
return self.title
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
was_published_recently.admin_order_field = 'pub_date'
was_published_recently.boolean = True
was_published_recently.short_description = 'Published recently?'
class Attribute(models.Model):
description = models.CharField(max_length=50)
def __unicode__(self):
return self.description
class JobAttribute(models.Model):
attribute_id = models.ForeignKey(Attribute)
job_id = models.ForeignKey(Job)
value = models.CharField(max_length=50)


and i'm going to write the pipeline.

In scrapy i have items:

from scrapy.contrib.djangoitem import DjangoItem
from jobs.models import Job, JobAttribute, Attribute

class JobItem(DjangoItem):
django_model = Job

class JobAttributeItem(DjangoItem):
django_model = JobAttribute

class AttributeItem(DjangoItem):
django_model = Attribute


in my spider i have:

item = JobItem()
item["url"] = response.url
item["title"] = 'something'
item['pub_date'] = 'something'
item["description"] = 'something'
item.save()



Everythings work fine. But now i want to save JobAttributeItem too:

item_jobattribute = JobAttributeItem()
item_jobattribute['job_id'] = 'want a job object'
item_jobattribute['attribute_id'] = 'what a attribute object'
item_jobattribute['value'] = 'something'
item_jobattribute.save()


how can i do this?
Thanks a lot

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




Re: A small bug for dynamic choices

2013-02-11 Thread vijay shanker
I found out that ('shoppingcart.models.Cart', 'Cart') is lost coz it 
doesnot finds any model_class (i.e model_class is None and is thus filtered 
out ) when i am running the code but it does finds the model_class from 
python shell.
something which is not very obvious is happening.  

On Monday, February 11, 2013 4:29:44 PM UTC+5:30, vijay shanker wrote:
>
> hi 
> i wrote a function for producing tuples of all model names, which is this:
> from django.contrib.contenttypes.models import ContentType
> from django.db.models.loading import get_model
>
> def get_all_models():
> return tuple([(each.__module__+'.'+each.__name__,each.__name__) for 
> each in [each.model_class() for each in 
> ContentType.objects.filter(app_label__in=['products','productoptions','shoppingcart'])
>  
> if each is not None] if each is not None])
> 
> when i run this in my shell it gives this output:
>
> (('shoppingcart.models.Cart', 'Cart'), ('shoppingcart.models.CartItem', 
> 'CartItem'), ('shoppingcart.models.CartRule', 'CartRule'), 
> ('products.models.CasesAccessory', 'CasesAccessory'), 
> ('productoptions.models.Coating', 'Coating'), 
> ('shoppingcart.models.ConditionSet', 'ConditionSet'), 
> ('products.models.Eyeglass', 'Eyeglass'), ('products.models.GiftVoucher', 
> 'GiftVoucher'), ('productoptions.models.Lens', 'Lens'), 
> ('productoptions.models.Prescription', 'Prescription'), 
> ('products.models.Readingglass', 'Readingglass'), 
> ('products.models.Sunglass', 'Sunglass'), ('productoptions.models.Tint', 
> 'Tint'), ('productoptions.models.Vision', 'Vision'))
>
> while at choices my first option got lost and output is:
>
> (('shoppingcart.models.CartItem', 'CartItem'), 
> ('products.models.CasesAccessory', 'CasesAccessory'), 
> ('productoptions.models.Coating', 'Coating'), ('products.models.Eyeglass', 
> 'Eyeglass'), ('products.models.GiftVoucher', 'GiftVoucher'), 
> ('productoptions.models.Lens', 'Lens'), 
> ('productoptions.models.Prescription', 'Prescription'), 
> ('products.models.Readingglass', 'Readingglass'), 
> ('products.models.Sunglass', 'Sunglass'), ('productoptions.models.Tint', 
> 'Tint'), ('productoptions.models.Vision', 'Vision'))
>
> why did this happened and whats the fix ?
>

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




Using template fragment caching *inside* a sitewide cache: possible?

2013-02-11 Thread Matt Andrews
Hi all,

I've been experimenting with an expensive query I need to call (essentially 
grabbing data from some Google APIs). I tried this experiment:

   - A sitewide cache with a long (days) expiry time
   - A template fragment with its own separate cache *inside* a view cached 
   by the sitewide cache -- this fragment simply displays the current time.
   - A view function which clears the named template fragment cache.

The behaviour I expected was that on first pageload, the fragment would 
display the time of page render, and all subsequent reloads would display 
the same time. This was true.

The second part, though, was that I expected to be able to call the view 
function to clear the fragment cache and then reload the page to see the 
time update. This didn't happen.

Is it possible to achieve this behaviour? Essentially I want to run a 
background cron task which just hits the Google API and updates my cached 
fragments - the Google data changes every 15 minutes but the sitewide cache 
has several hours timeout, normally.

Hope this makes sense.

Matt

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




Accessing REMOTE_USER in models/backend

2013-02-11 Thread fsang
Hi,

I am developing a Django application which will be accessed by it's users 
both via HTTP and through the Python shell. All of my models have a 
"touch_user" and "create_user" attribute, containing usernames in plain 
text. This is primarily used for logging purposes, nothing critical. My 
idea was that whenever a model's save method is being invoked that the 
"touch_user" attribute is set to the current username.

In the Python shell this is already working with getpass.getuser(). As you 
might have guessed already I also want to do this when the models are saved 
through the web, both in Django's admin as well as in my custom views. 
Since I do not want to add a custom save()-Method (I am using the 
pre_save() signal for this) I needed some way to access the username in the 
backend, without a HTTP request instance. So I created a custom middleware 
which stores the REMOTE_USER in os.environ like this:

def process_request(self, request):
if request.META.has_key('REMOTE_USER'):
os.environ['REMOTE_USER'] = request.META['REMOTE_USER']

Now while this approach works for me I'd like to know if there is a better 
way of doing this? Is this method even safe with Apache and mod_wsgi, or 
would threading.local be a better approach here? I am not using os.environ 
for authorization or anything mission-critical, but it'd still be good to 
know if this can go wrong.


Regards,
Frederik 

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




Re: Overall Design Question

2013-02-11 Thread Ajinkya Gadewar
Hi Alex,

I already have a education system developed. We run a software company in 
India. Let me know if you need more details on it.

Regards,
Ajinkya Gadewar

Sent from my iPhone

On 11-Feb-2013, at 2:17 PM, "alexandre...@gmail.com"  
wrote:

> Hi
> I'm starting a big app on Django for Shool management, to replace a Win32 app.
> 
> I've roles like teachers, students, admin stuff, ... that have diferent 
> access.
> How should it be developded?
> 
> 1- an app for each role?
> 2- some logic in templates?
> 3- any other
> 
> what is the correct aporach to get big and simple.
> 
> Regards
> Alex
> 
> -- 
> 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.
>  
>  

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




django-achievements: registering achievements

2013-02-11 Thread Henri
Newbie request here - could anyone elaborate on/explain the following quote 
from the django-achievements 
documentation.
 
I'm having a hard time wrapping my head around it.Thanks!

---

To register it into the engine just use the ‘*ACHIEVEMENT_CLASSES*‘ 
attribute in your settings like that :

#==#
 Achievements 
conf#==ACHIEVEMENT_CLASSES
 = ['accounts.handlers', 'backend.handlers']

The file where the classes are defined are not important, but try to avoid 
conflicts of naming by avoiding to use the name *achievements.py*.

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




Re: One ->Many forms outside admin

2013-02-11 Thread Jani Tiainen

11.2.2013 13:38, alexandre...@gmail.com kirjoitti:

I think taht is for editing a bunch of equal modelsat the same time...

I need to edit a 1-many relationship in the same manner admin does.

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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Inline formsets to be exact is something that you're looking for:

https://docs.djangoproject.com/en/1.4/topics/forms/modelforms/#inline-formsets

--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

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




Re: One ->Many forms outside admin

2013-02-11 Thread alexandre...@gmail.com
I think taht is for editing a bunch of equal modelsat the same time...

I need to edit a 1-many relationship in the same manner admin does.

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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




A small bug for dynamic choices

2013-02-11 Thread vijay shanker
hi 
i wrote a function for producing tuples of all model names, which is this:
from django.contrib.contenttypes.models import ContentType
from django.db.models.loading import get_model

def get_all_models():
return tuple([(each.__module__+'.'+each.__name__,each.__name__) for 
each in [each.model_class() for each in 
ContentType.objects.filter(app_label__in=['products','productoptions','shoppingcart'])
 
if each is not None] if each is not None])

when i run this in my shell it gives this output:

(('shoppingcart.models.Cart', 'Cart'), ('shoppingcart.models.CartItem', 
'CartItem'), ('shoppingcart.models.CartRule', 'CartRule'), 
('products.models.CasesAccessory', 'CasesAccessory'), 
('productoptions.models.Coating', 'Coating'), 
('shoppingcart.models.ConditionSet', 'ConditionSet'), 
('products.models.Eyeglass', 'Eyeglass'), ('products.models.GiftVoucher', 
'GiftVoucher'), ('productoptions.models.Lens', 'Lens'), 
('productoptions.models.Prescription', 'Prescription'), 
('products.models.Readingglass', 'Readingglass'), 
('products.models.Sunglass', 'Sunglass'), ('productoptions.models.Tint', 
'Tint'), ('productoptions.models.Vision', 'Vision'))

while at choices my first option got lost and output is:

(('shoppingcart.models.CartItem', 'CartItem'), 
('products.models.CasesAccessory', 'CasesAccessory'), 
('productoptions.models.Coating', 'Coating'), ('products.models.Eyeglass', 
'Eyeglass'), ('products.models.GiftVoucher', 'GiftVoucher'), 
('productoptions.models.Lens', 'Lens'), 
('productoptions.models.Prescription', 'Prescription'), 
('products.models.Readingglass', 'Readingglass'), 
('products.models.Sunglass', 'Sunglass'), ('productoptions.models.Tint', 
'Tint'), ('productoptions.models.Vision', 'Vision'))

why did this happened and whats the fix ?

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




Re: Replacing a model instance's __dict__

2013-02-11 Thread Tom Evans
Thanks for the advice guys, I didn't like it much either - a Friday
afternoon solution. I'll do something a little less brute force ;)

Cheers

Tom

On Sat, Feb 9, 2013 at 11:22 AM, Bill Freeman  wrote:
> Tom,
>
> I suspect that there man be problematic, perhaps dependent on python
> version, because the __dict__ attribute itself is a slot (it couldn't, for
> example, be in the __dict__).  Some slots may not accept assignment after
> creation, and the __dict__ object may not be an ordinary dict().
>
> Separately, if I'm understanding correctly, there is a local database with a
> copy of the information.  Unless you've done something special with the
> local model definitions, the id field will be problematic.
>
> I think that you're stuck with  a for loop over synched_contact.items(),
> where you can filter keys that shouldn't be saved.  You can also then uses
> setattr(self, key, value) instead of accessing self.__dict__, leaving you
> the flexibility for some of these attributes to be properties, if that turns
> out to be useful.
>
> Bill
>
> On Fri, Feb 8, 2013 at 12:50 PM, Tom Evans  wrote:
>>
>> Hi all
>>
>> I have a curious problem with a complex data replication issue.
>>
>> Basically, we use SalesForce as a CRM system. We also have a bunch of
>> users who aren't allowed a SF license due to cost reasons, and they
>> interact with SF via our own Django website that communicates to SF
>> via an API.
>>
>> With this API, we can CRUD all salesforce objects. We can also fetch
>> all changes since (specific time), so we maintain a local copy of all
>> our SF data in django models, synchronizing changes every 10 minutes
>> throughout the day. This actually works quite well!
>>
>> The problem comes with using django idioms like get_or_create(), when
>> an object is created directly on SF in the period since the last
>> synchronization. In this example, we want to get_or_create a Contact
>> with a specific email address. There is no Contact locally with the
>> specified email address, so get_or_create tries to create a new one.
>>
>> Using the API, this issues the appropriate query to SF, but since the
>> Contact already exists on SF, an exception is raised.
>>
>> get_or_create(), create() all work via save(), so my idea is to catch
>> this specific error in save, re-synchronise the database against the
>> remote end, pull the freshly synced record out of the database, and
>> replace self.__dict__ with new_item.__dict__, looking something like
>> this:
>>
>>   def save(self, *args, **kwargs):
>>   try:
>>   super(Contact, self).save(*args, **kwargs)
>>   except ValueError, e:
>>   if 'Contact already exists' in unicode(e):
>>   # Synchronize Contact objects with SF
>>   run_log = SyncRunLog(start_time=datetime.now())
>>   run_log.save()
>>   Contact.update(run_log)
>>   # The contact should now be available locally
>>   try:
>>   synched_contact = Contact.objects.get(email=self.email)
>>   self.__dict__ = synched_contact.__dict__
>>   except Contact.DoesNotExist:
>>   # Still not there, raise a new ValueError
>>   raise ValueError(
>>   'Failed to find contact %s after resyncing '
>>   'Contact following this error: %s'
>>   % (self.email, unicode(e)))
>>   else:
>>   raise e
>>
>> Is there an obvious issue with doing this? Can I simply replace
>> self.__dict__ like that without bad consequences?
>>
>> 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?hl=en.
>> 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?hl=en.
> 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?hl=en.
For more options, visit 

change select choices in django admin on select of another field

2013-02-11 Thread vijay shanker
Hi
I have a model called Place, which is like this:

class Place(models.Model):
 state = models.CharField(max_lengh=50, choices=STATE_CHOICES)
 city   = models.Charfield(max_length=50)

I want to populate select choices for repective city for state in admin, 
when the user selects the state. How should i do it ? 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: One ->Many forms outside admin

2013-02-11 Thread Jani Tiainen

Hi,

I think you're looking for (model) formsets.

11.2.2013 10:49, alexandre...@gmail.com kirjoitti:

Hi

I need to edit

1->many
   ->many  forms on my pages like in admin, using inlines, but outside admin

can anyone give clues on how to do it

Regards
Alex

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





--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

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




One ->Many forms outside admin

2013-02-11 Thread alexandre...@gmail.com
Hi

I need to edit  

1->many
  ->many  forms on my pages like in admin, using inlines, but outside admin

can anyone give clues on how to do it

Regards
Alex

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




Overall Design Question

2013-02-11 Thread alexandre...@gmail.com
Hi
I'm starting a big app on Django for Shool management, to replace a Win32 
app.

I've roles like teachers, students, admin stuff, ... that have diferent 
access.
How should it be developded?

1- an app for each role?
2- some logic in templates?
3- any other

what is the correct aporach to get big and simple.

Regards
Alex

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