Re: Any Django users in Reims (France) ?

2013-08-20 Thread anthony tresontani

Salut,

Je suis sur Metz mais ca peut m'intéressé :)

Anthony

Le 21/08/2013 08:28, Fabrice Romand a écrit :

Bonjour,
Je cherche des dev Django dans la région de Reims (France)
pour organiser des rencontres sympas et échanger sur notre plateforme 
préférée

voire développer ensemble nos excellentes idées.
A votre écoute,
Fabrice
--
You received this message because you are subscribed to the Google 
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to django-users+unsubscr...@googlegroups.com.

To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Using django.contrib.auth...

2013-08-20 Thread Nigel Legg
Thanks very much Laurent, I will have a go with that this morning. 
Regards, N/ 

On Monday, 19 August 2013 16:25:00 UTC+1, Laurent Meunier wrote:
>
> On 19/08/2013 17:05, Nigel Legg wrote: 
> > In the app I am building for data analysis, I want all logged in users 
> > to be able to access all parts of the system, but only to have access to 
> > the datafiles they hae uploaded themselves.  Can I use 
> > django.contrib.auth to filter the full list of datafiles according to 
> > the user object? 
> > If so, how do I go about this? I'm thinking of attaching a user_id field 
> > to the file when it is uploaded, and then filtering against that wen a 
> > logged in user goes to the list of files, but I'm not sure how I would 
> > implement this. 
> > Any help greatly appreciated. 
>
> Hi, 
>
> Your best option is to add a foreign key to your user model (usually 
> django.contrib.auth.models.User) in your model that handles your 
> datafiles. 
>
> from django.contrib.auth.models import User 
>
> class Datafile(models.Model): 
>  user = models.ForeignKey(User) 
>  ... 
>
>
> When a user upload a datafile, don't forget to set the user field: 
>
> mydatafile.user = request.user 
>
>
> And then you can filter datafiles: 
>
> Datafile.objects.filter(user=request.user) 
>
>
> -- 
> Laurent Meunier > 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Any Django users in Reims (France) ?

2013-08-20 Thread Fabrice Romand
Bonjour,
Je cherche des dev Django dans la région de Reims (France) 
pour organiser des rencontres sympas et échanger sur notre plateforme 
préférée
voire développer ensemble nos excellentes idées.
A votre écoute,
Fabrice

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: online Django users directory ?

2013-08-20 Thread Fabrice Romand
mainely finding people who offering/searching django skill for local job, 
help, exchange
others ideas ?

Le mercredi 21 août 2013 07:31:37 UTC+2, אברהם סרור a écrit :
>
> What for?
> On Aug 21, 2013 12:04 AM, "Fabrice Romand" 
> > 
> wrote:
>
>> Hi,
>>
>> Do you know any online Django users directory ?
>>
>> if not, will you support a such project ?
>>
>>
>>  -- 
>> 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.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: online Django users directory ?

2013-08-20 Thread Avraham Serour
What for?
On Aug 21, 2013 12:04 AM, "Fabrice Romand"  wrote:

> Hi,
>
> Do you know any online Django users directory ?
>
> if not, will you support a such project ?
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: ManyToManyField select only results that match

2013-08-20 Thread Gerd Koetje
mm that seems to not work when i do it on multiple field

kleurogen = models.ManyToManyField(Keuzes, blank=True, null=True)
kleurhaar = models.ManyToManyField(Keuzes, blank=True, null=True)


django.core.management.base.CommandError: One or more models did not 
validate:

profielen.profielen: Accessor for m2m field 'kleurogen' clashes with 
related m2m field 'Keuzes.profielen_set'. Add a related_name argument to 
the definition for 'kleurogen'.
profielen.profielen: Accessor for m2m field 'kleurhaar' clashes with 
related m2m field 'Keuzes.profielen_set'. Add a related_name argument to 
the definition for 'kleurhaar'.


and when i do this is shows all the results again instead of the selected

kleurogen = models.ManyToManyField(Keuzes, related_name='keuzes_kleurogen', 
blank=True, null=True)
kleurhaar = models.ManyToManyField(Keuzes, related_name='keuzes_kleurhaar', 
blank=True, null=True)



what am i doing wrong?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: ManyToManyField select only results that match

2013-08-20 Thread Gerd Koetje
i think i got it, i was foing it at the wrong spot.

i added this to my forms.py

kleurogen = 
forms.ModelMultipleChoiceField(queryset=Keuzes.objects.filter(groep_id=
'kleurogen'))


works like a charm

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


ManyToManyField select only results that match

2013-08-20 Thread Gerd Koetje
Hi all,

I got a form where i use a manytomany field likes this


kleurogen = models.ManyToManyField(Keuzes, blank=True, null=True)

This works fine but takes all the results from Keuzes
How can i only get the results from Keuzes that have the groep 'kleurogen'

i tried this but it doesnt work

kleurogen = models.ManyToManyField(Keuzes.objects.filter(groep_id=
"kleurogen"), blank=True, null=True)

AssertionError: ManyToManyField([, ]) is 
invalid. First parameter to ManyToManyField must be either a model, a model 
name, or the string 'self'

How can i do this?


in Keuzes i have

class Keuzes (models.Model):

name = models.CharField(max_length=255)

groep = models.ForeignKey(Keuzegroepen)



def __unicode__(self):

return self.name


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Bulk-creating two ForeignKey linked models - id field for relationship isn't set properly?

2013-08-20 Thread Victor Hooi
Hi,

Cool, thanks for the link to the ticket. Very interesting reading, and I
learnt something =).

Apparently the ticket says the patch still needs docs/tests - guess it'll
be a while before this gets integrated then...hmm.

Cheers,
Victor


On Wed, Aug 21, 2013 at 2:11 AM, Simon Charette wrote:

> This is a known limitation of `bulk_create`: objects used for bulk
> creation are not assigned a primary 
> key
> .
>
> Le mardi 20 août 2013 05:57:52 UTC-4, Victor Hooi a écrit :
>
>> Hi,
>>
>> *1. Bulk Creating Products/ProductImages*
>>
>> I have a Django custom management command that bulk-loads a list of
>> products and product images from a JSON file.
>>
>> I have a Product model, along with an ProductImage model - each Product
>> may have many ProductImages.
>>
>> class Product(models.Model):
>>> ...
>>> name = models.CharField(max_length=**200, help_text='Name of this
>>> product.')
>>> description = models.TextField(help_text='**Short description of
>>> this product.')
>>> external_id = models.CharField(max_length=**100, unique=True,
>>> help_text='Unique identifier for this product provided by the supplier.')
>>> brand = models.ForeignKey(Brand)
>>> supplier = models.ForeignKey(Supplier)
>>> selling_price = models.DecimalField(max_**digits=10,
>>> decimal_places=2, help_text='The price which we\'re selling this product
>>> at.')
>>> original_price = models.DecimalField(max_**digits=10,
>>> decimal_places=2, help_text='The original retail price of this product,
>>> before any discounts.')
>>> current_stock_level = models.PositiveIntegerField(**default=0)
>>> current_sold_count = models.PositiveIntegerField(**default=0)
>>> ...
>>
>>
>> class ProductImage(models.Model):
>>> product = models.ForeignKey(Product, related_name='images')
>>> image = models.ImageField(max_length=**200,
>>> upload_to='product_images')
>>> # TODO - Do we actually want to make retina images a distinct column
>>> in the database? May need to revisit this.
>>> retina_image = models.ImageField(max_length=**200,
>>> upload_to='product_images')
>>> size = models.ForeignKey(ImageSize)
>>> ordinal = models.PositiveIntegerField(**default=0)
>>> class Meta:
>>> ordering = ['ordinal']
>>> unique_together = ('product', 'size', 'ordinal')
>>> def __unicode__(self):
>>> return u'%s image %i for %s' % (self.size, self.ordinal,
>>> self.product.name)
>>
>>
>> I have a single look that iterates through the JSON file, creating a list
>> of Products, as well as a list of ProductImages that link back to those
>> products. (The below is an extract)
>>
>> products = []
>>> product_images = []
>>> ...
>>> for product in json_data:
>>> brand, created_new_brand = Brand.objects.get_or_create(**
>>> name=product['brand'])
>>> if created_new_brand:
>>> new_brands_created += 1
>>> ...
>>> current_product = Product(name = product['name'],
>>> brand = brand,
>>> supplier = supplier,
>>> description =
>>> product['description'],
>>> ...
>>> )
>>> ...
>>> for image_set in product['images']:
>>> for size in image_sizes.keys():
>>> product_images.append(**ProductImage(product =
>>> current_product,
>>>image =
>>> image_set[size],
>>>retina_image
>>> = image_set[size],
>>>size =
>>> image_sizes[size],
>>>ordinal =
>>> image_set_counter,
>>>))
>>> image_set_counter += 1
>>> ...
>>> Product.objects.bulk_create(**products)
>>> ...
>>> for product_image in product_images:
>>> product_image.save()
>>
>>
>> I then call bulk_create() on the products list, which succeeds.
>>
>> However, when I try to call .save() or bulk_create() on the ProductImage,
>> they fail, saying that product_id is NULL.
>>
>> IntegrityError: null value in column "product_id" violates not-null
>>> constraint
>>> DETAIL:  Failing row contains (8, null, https://cdn.foobar.com.au/**
>>> site_media/uploads/product_im.**..,
>>> https://cdn.foobar.com.au/**site_media/uploads/product_im.**..,
>>> 4, 0).
>>
>>
>> If I actually inspect one one of the items in the ProductImages list -
>> product_image.product seems to point to a v

Re: Bulk-creating two ForeignKey linked models - id field for relationship isn't set properly?

2013-08-20 Thread Victor Hooi
Hi,

In the source file (JSON) - I have a list of Products dictionaries.

The images are one of the elements in that dictionary - hence, the link 
between them is that images is a child of Product.

Hence, when I loop through to create Product, I can create the images and 
link it there.

At the end, the ProductImage objects all have a valid Product field, but no 
valid Product_id field - perhaps I can create all the 
Products/ProductImages, do a bulk_create() on the Products, then do a 
lookup for each ProductImage for that Product and assign a valid product_id?

However, not sure whether doing that extra lookup is going to be any better 
than just iterating through and doing a save() each round and avoiding 
bulk_create() altogether.

Cheers,
Victor

On Tuesday, 20 August 2013 22:51:57 UTC+10, Daniel Roseman wrote:
>
> On Tuesday, 20 August 2013 12:10:34 UTC+1, Victor Hooi wrote:
>
>> Hi,
>>
>> 1. Hmm, in that case, using bulk_create may not work - I'm currently 
>> relying on generating the full lists of Products and ProductImages, then 
>> saving in a batch at the end.
>>
>> So I need to loop through and call .save() individually on each Product, 
>> then the corresponding ProductImages, before moving onto the next Product().
>>
>> Are there any workarounds for this, or any way I could still leverage on 
>> bulk_create()?
>>
>>
> Can you bulk save the Products first, then assign them to the 
> ProductImages and bulk save those?
> --
> DR.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


online Django users directory ?

2013-08-20 Thread Fabrice Romand
Hi,

Do you know any online Django users directory ?

if not, will you support a such project ?


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Periodic tasks

2013-08-20 Thread Arnold Krille
On Sat, 17 Aug 2013 03:36:29 +0100 Some Developer
 wrote:
> I'm aware of django-cron and django-celery, both of which are capable
> of doing what I want but I was wondering if I was just making a
> fundamental design mistake and there maybe a better option that
> someone here could explain.
> 
> Basically customers pay money into their account in advance so that
> they can use services that we offer. Each service is charged by the
> minute and prices between services can vary wildly. I need to be able
> to show our clients their current running total to the nearest hour
> so that they know when they need to add extra funds to their account.
> 
> My initial thought was that I would just have the equivalent of a
> cron job running every hour that queries the database for the state
> of each users application and then used that to produce an estimate
> for their current billing.
> 
> Alternately I could get rid of the hourly period task and just work
> it out when a customer visits a certain page but that is likely to
> lead to long load times and heavy database use.
> 
> Any suggestions on what you would do in this situation?

Calculate the value on each visit for now.
Worry about the execution-time when your database actually has lots of
users, payments and service-charges applied and the site does get slow
to load. Then use django-debug-toolbar to see how many queries your are
running to calculate the number and how long these queries take. Try to
reduce the number of queries, do whatever you can in the database
instead of in python.
When you have reached your end of wisdom while optimizing the
algorithm and the sql (or djangos use of sql through the orm), start
looking into celery/cron/django-extensions. While celery _can_ do
regular jobs, its not really its primary use. And probably not worth
setting up celery+redis when you only want it to do cron-jobs. If you
need celery for other stuff already, then use it for cron-jobs too. But
otherwise its probably better to look at the cronjobs-framework of
django-extensions.

Have fun,

Arnold


signature.asc
Description: PGP signature


Re: Any Tutorials on Django similar to Web2py ????????????????

2013-08-20 Thread Rich Haase
I second the book recommendation.  I had a cursory knowledge of django
(enough to get myself in trouble) prior to reading 2 scoops of django.  Now
I have enough knowledge to really make a mess... j/k.  It's a great book
for learning about the nitty gritty of django development and informing the
questions you will ask.

Cheers,

rich


On Tue, Aug 20, 2013 at 12:48 PM, Sergio Infante Montero <
raulserg...@gmail.com> wrote:

> Maybe, you need some book like this
>
> https://django.2scoops.org/
>
> Regards
>
> On Tue, Aug 20, 2013 at 11:21 AM, Marcos Moyano 
> wrote:
> > There are several ways to manage sessions, or cache. That's up to you
> > according to your needs.
> > You can find documentation about sessions, caching and much more here:
> > https://docs.djangoproject.com/en/1.5/
> >
> > Rgds
> >
> >
> > On Tue, Aug 20, 2013 at 1:12 PM, JAI PRAKASH SINGH
> >  wrote:
> >>
> >> Thank you sir, but i need that kind of tutorials which is complete , in
> >> terms of security, session, cache like udacity  tutorilas on web2py ..
> on
> >> web development.
> >>
> >> Please revert back if u have any kind of link on it
> >>
> >>
> >> On Tue, Aug 20, 2013 at 9:35 PM, carlos  wrote:
> >>>
> >>> https://docs.djangoproject.com/en/1.5/intro/tutorial01/
> >>>
> >>> Cheers
> >>>
> >>>
> >>> On Tue, Aug 20, 2013 at 9:57 AM, JAI PRAKASH SINGH
> >>>  wrote:
> 
>  Any Tutorials on Django similar to Web2py 
> 
>  --
>  You received this message because you are subscribed to the Google
>  Groups "Django users" group.
>  To unsubscribe from this group and stop receiving emails from it, send
>  an email to django-users+unsubscr...@googlegroups.com.
> 
>  To post to this group, send email to django-users@googlegroups.com.
>  Visit this group at http://groups.google.com/group/django-users.
>  For more options, visit https://groups.google.com/groups/opt_out.
> >>>
> >>>
> >>> --
> >>> You received this message because you are subscribed to a topic in the
> >>> Google Groups "Django users" group.
> >>> To unsubscribe from this topic, visit
> >>> https://groups.google.com/d/topic/django-users/8i61qvs2tn4/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.
> >>> For more options, visit https://groups.google.com/groups/opt_out.
> >>
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "Django users" group.
> >> To unsubscribe from this group and stop receiving emails from it, send
> an
> >> email to django-users+unsubscr...@googlegroups.com.
> >> To post to this group, send email to django-users@googlegroups.com.
> >> Visit this group at http://groups.google.com/group/django-users.
> >> For more options, visit https://groups.google.com/groups/opt_out.
> >
> >
> >
> >
> > --
> > Some people, when confronted with a problem, think “I know, I'll use
> regular
> > expressions.” Now they have two problems.
> >
> > Jamie Zawinski, in comp.emacs.xemacs
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to django-users+unsubscr...@googlegroups.com.
> > To post to this group, send email to django-users@googlegroups.com.
> > Visit this group at http://groups.google.com/group/django-users.
> > For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
> --
> Sergio Infante Montero
> http://about.me/neosergio
> @neosergio
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
*Kernighan's Law*
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it."

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Any Tutorials on Django similar to Web2py ????????????????

2013-08-20 Thread Sergio Infante Montero
Maybe, you need some book like this

https://django.2scoops.org/

Regards

On Tue, Aug 20, 2013 at 11:21 AM, Marcos Moyano  wrote:
> There are several ways to manage sessions, or cache. That's up to you
> according to your needs.
> You can find documentation about sessions, caching and much more here:
> https://docs.djangoproject.com/en/1.5/
>
> Rgds
>
>
> On Tue, Aug 20, 2013 at 1:12 PM, JAI PRAKASH SINGH
>  wrote:
>>
>> Thank you sir, but i need that kind of tutorials which is complete , in
>> terms of security, session, cache like udacity  tutorilas on web2py .. on
>> web development.
>>
>> Please revert back if u have any kind of link on it
>>
>>
>> On Tue, Aug 20, 2013 at 9:35 PM, carlos  wrote:
>>>
>>> https://docs.djangoproject.com/en/1.5/intro/tutorial01/
>>>
>>> Cheers
>>>
>>>
>>> On Tue, Aug 20, 2013 at 9:57 AM, JAI PRAKASH SINGH
>>>  wrote:

 Any Tutorials on Django similar to Web2py 

 --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to django-users+unsubscr...@googlegroups.com.

 To post to this group, send email to django-users@googlegroups.com.
 Visit this group at http://groups.google.com/group/django-users.
 For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "Django users" group.
>>> To unsubscribe from this topic, visit
>>> https://groups.google.com/d/topic/django-users/8i61qvs2tn4/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.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
>
> --
> Some people, when confronted with a problem, think “I know, I'll use regular
> expressions.” Now they have two problems.
>
> Jamie Zawinski, in comp.emacs.xemacs
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.



-- 
Sergio Infante Montero
http://about.me/neosergio
@neosergio

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Adding custom WHERE conditions to query sets (MySQL user defined functions)

2013-08-20 Thread Jon Dufresne
Hi,

My Django application was ported from a legacy application. This legacy
application has some MySQL user defined functions that are frequently used
in the WHERE clause of queries. Is it possible to use these stored
functions and still return query sets? I want to do something like

MyModel.objects.filter(field_one='blah',
field_two='blah').call('my_function(,
)').order_by('field_three')

Is anything like this possible or do I need to resort to custom SQL? I
don't mind if I need to write a custom QuerySet or Manager. I am concerned
about using custom SQL as most operation and views seem to prefer lazy
query sets instead of lists of models.

Thanks for any help.
Jon

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Representing infinity or "no limit" in an integer field?

2013-08-20 Thread Jason Arnst-Goodrich
To be honest, I've never dealt with huge data sets but in the cases I have 
dealt with it's never been a problem.

This might be relevant: 
http://dev.mysql.com/doc/refman/5.0/en/is-null-optimization.html

Unless someone shows me pretty compelling stats otherwise, I'll always lean 
to implementing in a way that makes sense logically and worry about 
performance optimizations when they come up. Storing Nulls just make sense 
to achieve the goal so that's what I'd do until there's a reason for me not 
to.

On Tuesday, August 20, 2013 3:46:16 AM UTC-7, Jani Tiainen wrote:
>
> On Mon, 19 Aug 2013 11:14:54 -0700 (PDT) 
> Jason Arnst-Goodrich > wrote: 
>
> > 
> > > 
> > > Problem is that usually databases aren't very fast to search NULL 
> values 
> > > so if you have to for example produce often list of products that you 
> can 
> > > buy "infinite amount", you would like to consider using value(s) that 
> don't 
> > > conflict from valid set of values. 
> > 
> > 
> > I'm pretty sure that's not true. 
>
> My knowledge is limited per implementation but as far as I know, standard 
> implementation is not to include NULL's (since NULL means "does not 
> exist"). 
>
> I think pretty latest PostgreSQL can use indexes to filter NULL values as 
> well (doesn't have facility to store them though). Oracle since 11g has 
> option to include null values in the index. 
>
> MySQL uses table statistics to determine are NULL values indexed or not. 
>
> For the rest I don't have knowledge about. 
>
> That doesn't remove the fact that there will be a limit for ordering one 
> time - though I would be happy to know what "unlimited" amount of ordering 
> would mean and how to actually it would be implemented and what's the real 
> world use case... 
>
> > +1 to store as Null. 
> > 
> > On Monday, August 19, 2013 1:07:27 AM UTC-7, Jani Tiainen wrote: 
> > > 
> > > On Mon, 19 Aug 2013 00:39:09 -0700 (PDT) 
> > > Victor Hooi > wrote: 
> > > 
> > > > Hi, 
> > > > 
> > > > I have a Django IntegerField that I'm using to store the purchase 
> limit 
> > > for 
> > > > a product. 
> > > > 
> > > > purchase_limit = models.IntegerField() 
> > > > 
> > > > 
> > > > I also need to represent no limit (i.e. infinity) as well in that 
> field. 
> > > > 
> > > > I was thinking of just using NULL to represent no limit. 
> > > > 
> > > > purchase_limit = models.IntegerField(blank=True, null=True) 
> > > > 
> > > > 
> > > > Zero would have a meaning for this field (you can't buy any), 
> however 
> > > > negative numbers don't have any meaning. 
> > > > 
> > > > Hence, another option is just to use say, -1 as the value to 
> represent 
> > > no 
> > > > limit. 
> > > > 
> > > > Any thoughts on either option, or which one is more "correct"? 
> > > 
> > > From mathematical point integers forms an infinite (countable) set. 
> Though 
> > > in computer science interger is usually a finite set. So what you need 
> is 
> > > just define a logic. Note that this also makes impossible to enforce 
> > > "unlimited" amount to buy so there will definitely be some maximum 
> amount 
> > > you can really buy. 
> > > 
> > > NULL is usually interpreted as "no value defined" which would suit 
> well in 
> > > that sense. Problem is that usually databases aren't very fast to 
> search 
> > > NULL values so if you have to for example produce often list of 
> products 
> > > that you can buy "infinite amount", you would like to consider using 
> > > value(s) that don't conflict from valid set of values. 
> > > 
> > > I personally would pick max value while leaving NULL to mean "no value 
> > > defined". 
> > > 
> > > -- 
> > > 
> > > Jani Tiainen 
> > > 
> > 
> > -- 
> > 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. 
> > For more options, visit https://groups.google.com/groups/opt_out. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Admin CSS missing

2013-08-20 Thread Glenn Vulkers
And it's working, thanks alot!

Op dinsdag 20 augustus 2013 18:35:35 UTC+2 schreef Glenn Vulkers:
>
> Hello everyone,
>
> I'm just reading throught djangobook.com where I came to Chapter 6 so 
> far. It's about The Django Admin. I installed the admin and such
> but I notice that the CSS is missing. Does anyone know what to do? I'm 
> running Python2.7
>
> Glenn
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Admin CSS missing

2013-08-20 Thread Alex Franco
There you have your problem and answer... uncomment these lines:

   # 'django.middleware.csrf.CsrfViewMiddleware',

# 'django.contrib.sites',
# 'django.contrib.staticfiles',
# 'django.contrib.admin',

Voilà!

--
@jafrancov


On Tuesday, August 20, 2013 11:59:28 AM UTC-5, Glenn Vulkers wrote:
>
> I'm running manage.py runserver.
> Django version is: 1.5.1
>
> in Settings.py I have this:
>
> MIDDLEWARE_CLASSES = (
>  'django.middleware.common.CommonMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
> # 'django.middleware.csrf.CsrfViewMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware',
>  'django.contrib.messages.middleware.MessageMiddleware',
> # Uncomment the next line for simple clickjacking protection:
> # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
> )
>
> And this:
>
> INSTALLED_APPS = (
>  'django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
> # 'django.contrib.sites',
>  'django.contrib.messages',
> # 'django.contrib.staticfiles',
> # Uncomment the next line to enable the admin:
> # 'django.contrib.admin',
> # Uncomment the next line to enable admin documentation:
> # 'django.contrib.admindocs',
> 'books',
> 'django.contrib.admin',
> )
>
> And then did syncdb in the shell.
>
> In urls.py :
> from django.contrib import admin
> admin.autodiscover()
>
> And made a urlpatterns
>
>
>
>
> Op dinsdag 20 augustus 2013 18:44:09 UTC+2 schreef ke1g:
>>
>> Not enough information.
>>
>> Django works fine with python2.7, so we would need to know, for example, 
>> which version of Django, how you installed it, whether you are using 
>> manage.py runserver or whether you are running behind Apache or something 
>> else, and what exactly you mean by "I installed the admin and such"
>>
>>
>> On Tue, Aug 20, 2013 at 12:35 PM, Glenn Vulkers > > wrote:
>>
>>> Hello everyone,
>>>
>>> I'm just reading throught djangobook.com where I came to Chapter 6 so 
>>> far. It's about The Django Admin. I installed the admin and such
>>> but I notice that the CSS is missing. Does anyone know what to do? I'm 
>>> running Python2.7
>>>
>>> Glenn
>>>
>>> -- 
>>> 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.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Admin CSS missing

2013-08-20 Thread Glenn Vulkers
I'm running manage.py runserver.
Django version is: 1.5.1

in Settings.py I have this:

MIDDLEWARE_CLASSES = (
 'django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

And this:

INSTALLED_APPS = (
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
# 'django.contrib.sites',
 'django.contrib.messages',
# 'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'books',
'django.contrib.admin',
)

And then did syncdb in the shell.

In urls.py :
from django.contrib import admin
admin.autodiscover()

And made a urlpatterns




Op dinsdag 20 augustus 2013 18:44:09 UTC+2 schreef ke1g:
>
> Not enough information.
>
> Django works fine with python2.7, so we would need to know, for example, 
> which version of Django, how you installed it, whether you are using 
> manage.py runserver or whether you are running behind Apache or something 
> else, and what exactly you mean by "I installed the admin and such"
>
>
> On Tue, Aug 20, 2013 at 12:35 PM, Glenn Vulkers 
> 
> > wrote:
>
>> Hello everyone,
>>
>> I'm just reading throught djangobook.com where I came to Chapter 6 so 
>> far. It's about The Django Admin. I installed the admin and such
>> but I notice that the CSS is missing. Does anyone know what to do? I'm 
>> running Python2.7
>>
>> Glenn
>>
>> -- 
>> 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.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Admin CSS missing

2013-08-20 Thread Alex Franco
Are not missing, but if you are following the djangobook you probably 
commented something in your settings file as you did on chapter 5, review 
the middleware, staticfiles and templeate loaders lines, the issue is 
probably there.

On Tuesday, August 20, 2013 11:35:35 AM UTC-5, Glenn Vulkers wrote:
>
> Hello everyone,
>
> I'm just reading throught djangobook.com where I came to Chapter 6 so 
> far. It's about The Django Admin. I installed the admin and such
> but I notice that the CSS is missing. Does anyone know what to do? I'm 
> running Python2.7
>
> Glenn
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django Admin CSS missing

2013-08-20 Thread Bill Freeman
Not enough information.

Django works fine with python2.7, so we would need to know, for example,
which version of Django, how you installed it, whether you are using
manage.py runserver or whether you are running behind Apache or something
else, and what exactly you mean by "I installed the admin and such"


On Tue, Aug 20, 2013 at 12:35 PM, Glenn Vulkers <
luksindit-tjopt...@hotmail.com> wrote:

> Hello everyone,
>
> I'm just reading throught djangobook.com where I came to Chapter 6 so
> far. It's about The Django Admin. I installed the admin and such
> but I notice that the CSS is missing. Does anyone know what to do? I'm
> running Python2.7
>
> Glenn
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Django Admin CSS missing

2013-08-20 Thread Glenn Vulkers
Hello everyone,

I'm just reading throught djangobook.com where I came to Chapter 6 so far. 
It's about The Django Admin. I installed the admin and such
but I notice that the CSS is missing. Does anyone know what to do? I'm 
running Python2.7

Glenn

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Any Tutorials on Django similar to Web2py ????????????????

2013-08-20 Thread Marcos Moyano
There are several ways to manage sessions, or cache. That's up to you
according to your needs.
You can find documentation about sessions, caching and much more here:
https://docs.djangoproject.com/en/1.5/

Rgds


On Tue, Aug 20, 2013 at 1:12 PM, JAI PRAKASH SINGH <
jaiprakashsingh...@gmail.com> wrote:

> Thank you sir, but i need that kind of tutorials which is complete , in
> terms of security, session, cache like udacity  tutorilas on web2py .. on
> web development.
>
> Please revert back if u have any kind of link on it
>
>
> On Tue, Aug 20, 2013 at 9:35 PM, carlos  wrote:
>
>> https://docs.djangoproject.com/en/1.5/intro/tutorial01/
>>
>> Cheers
>>
>>
>> On Tue, Aug 20, 2013 at 9:57 AM, JAI PRAKASH SINGH <
>> jaiprakashsingh...@gmail.com> wrote:
>>
>>>  Any Tutorials on Django similar to Web2py 
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>>
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>>  --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/8i61qvs2tn4/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.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
Some people, when confronted with a problem, think “I know, I'll use
regular expressions.” Now they have two problems.

Jamie Zawinski, in comp.emacs.xemacs

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Any Tutorials on Django similar to Web2py ????????????????

2013-08-20 Thread JAI PRAKASH SINGH
Thank you sir, but i need that kind of tutorials which is complete , in
terms of security, session, cache like udacity  tutorilas on web2py .. on
web development.

Please revert back if u have any kind of link on it


On Tue, Aug 20, 2013 at 9:35 PM, carlos  wrote:

> https://docs.djangoproject.com/en/1.5/intro/tutorial01/
>
> Cheers
>
>
> On Tue, Aug 20, 2013 at 9:57 AM, JAI PRAKASH SINGH <
> jaiprakashsingh...@gmail.com> wrote:
>
>> Any Tutorials on Django similar to Web2py 
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>>
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/8i61qvs2tn4/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.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Any Tutorials on Django similar to Web2py ????????????????

2013-08-20 Thread carlos
https://docs.djangoproject.com/en/1.5/intro/tutorial01/

Cheers


On Tue, Aug 20, 2013 at 9:57 AM, JAI PRAKASH SINGH <
jaiprakashsingh...@gmail.com> wrote:

> Any Tutorials on Django similar to Web2py 
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Any Tutorials on Django similar to Web2py ????????????????

2013-08-20 Thread JAI PRAKASH SINGH
Any Tutorials on Django similar to Web2py 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Defining custom template tags in a new app

2013-08-20 Thread Tom Evans
On Tue, Aug 20, 2013 at 1:54 PM, Daniel Roseman  wrote:
> Django doesn't care what app the tags are in, as long as that app is in
> INSTALLED_APPS and the tags are in the templatetags directory inside the app
> (and Python requires a blank __init__.py in that directory too).

A slight follow up on what Daniel said - Django will iterate through
your installed apps until it can load a tag library with the
appropriate name from that app, at which point it stops trying to load
it. Therefore, if you use a common name for your library like 'tags',
you may be unexpectedly loading a tag library from a different app -
perhaps one that you didn't even know about.

So be sure to use a distinctive name!

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


extending from django.contrib.sites.models import Site

2013-08-20 Thread Gerd Koetje
is it possible to extend  

from django.contrib.sites.models import Site


Coudlnt find any help related

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Best-practice for "join mailing list" form on every page

2013-08-20 Thread Tom Evans
On Mon, Aug 19, 2013 at 8:18 PM, Steven Smith  wrote:
> I've got a simple form with one field that appears in the footer of my site,
> asking users to enter their email address to subscribe to our mailing list.
>
> Rather than duplicate the form-processing logic in every single view, what
> should I do?
> - POST to one location, but use a context processor to add the form in GET
> contexts?
> - Add a decorator to every view that does the form logic
> - Some other third option?
>
> What do people typically do in this type of situation?

A form with one field that appears on every single page? I'd choose
option 3, POST to one location, write out the form by hand in your
master template.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: How do I create a script to fill in django admin login form and submit?

2013-08-20 Thread 7equivalents
I feel as if I'm getting closer, yet haven't successfully  logged in yet. I 
have added in the missing key. I went to the django.contrib.auth.forms to 
find the name of the form that gets submitted in the login page. It seems 
to be called AuthenticationForm.

import requests
login_url = "http://192.168.0.21/admin/login/";


client = requests.session()
client.get(login_url)


csrftoken = client.cookies['csrftoken']


login_data = {'username':'jim', 'password':'beam', 
'AuthenticationForm':'1', 'csrfmiddlewaretoken':csrftoken}


r = client.post(login_url, data=login_data)


Basically after I do this from the python shell, I use another machine to 
log into the admin page and look at user logins, and the user is not logged 
in. Not sure how to proceed.


On Monday, August 19, 2013 12:13:21 AM UTC-4, WongoBongo wrote:
>
> You were missing a key. The following works on my machine.
>
> K
>
> ---
>
>
> import requests
> login_url = "http://192.168.0.21/admin/login/";
>
>
> client = requests.session()
> client.get(login_url)
>
>
> csrftoken = client.cookies['csrftoken']
>
>
> login_data = {'username':'jim', 'password':'beam', 
> 'this_is_the_login_form':'1', 'csrfmiddlewaretoken':csrftoken}
>
>
> r = client.post(login_url, data=login_data)
>
>
> target_url = "http://192.168.0.21/admin/auth/user/";
> t = client.get(target_url)
>
>
> 'Select user to change' in t.text # True 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Job Opportunity @ Dartmouth (Hanover, NH)

2013-08-20 Thread Casey Greene
Hi django-users,

I wanted to let you guys know about a job opportunity in my lab for a
position where we'd like to have someone with django expertise. The listing
is available through the Dartmouth jobs website:
https://searchjobs.dartmouth.edu/postings/20736

This position is on site in our lab located in Hanover, NH (
http://en.wikipedia.org/wiki/Hanover,_New_Hampshire ) in The Geisel School
of Medicine at Dartmouth (
http://en.wikipedia.org/wiki/Geisel_School_of_Medicine ).

Job Description:

In a cover letter please provide, if possible, examples of code
contributions (Bitbucket, GitHub, etc.) and/or contributions via
StackOverflow to demonstrate expertise.

Key Accountabilities:

Programming

   - Develops and writes computer programs to integrate genome-scale
   experiments and predict traits, drug treatment response, and other
   endpoints.
   - Designs, codes, tests, and documents such programs.
   - Adapts, improves, and debugs existing libraries.
   - Develops standalone programs and webservers for the analysis and
   visualization of large experimental compendia.
   - Optimizes existing systems that integrate and analyze large data
   compendia.

Skills & Knowledge:

   - Expertise in either Python and Javascript or similar languages with
   ability to rapidly transition to Python/Javascript.
   - Ability to work productively and communicate effectively with people
   of varying technical backgrounds.
   - Knowledge of or interest in genomics or molecular biology is highly
   desirable.
   - Understanding of software architecture, OO principles, and design
   patterns is desirable.
   - Expertise in web-software development is desirable.

Experience:

   - Experience with relational databases and web-development.
   - Professional experience including QA and user interface design is
   desirable.
   - Experience with D3.js, and Django is desirable.

Education:

   - Bachelor’s degree in Computer Science or a closely related field.

Additional Information/Instructions:

This position is funded by a grant. Continuation is based upon available
funds.

Employment in this position is contingent upon consent to and successful
completion of a pre-employment background check, which may include a
criminal background check, reference checks, verification of work history,
and verification of any required academic credentials, licenses, and/or
certifications, with results acceptable to Dartmouth College. A criminal
conviction will not automatically disqualify an applicant from employment.
Background check information will be used in a confidential,
non-discriminatory manner consistent with state and federal law.
Thanks!
Casey

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Defining custom template tags in a new app

2013-08-20 Thread Tom Lockhart

On 2013-08-20, at 3:53 AM, kandelabr  wrote:

> Hello!
> 
> I want to define a new template tag and use it in a number of applications 
> inside my django project. The documentation says:
> 
> Custom template tags and filters must live inside a Django app. If they 
> relate to an existing app it makes sense to bundle them there; otherwise, you 
> should create a new app to hold them.
> 
> But I could not find a word in documentation on how to {% load %} tags from 
> another app. I added the new 'custom_tags' app it to INSTALLED_APPS, 
> registered, imported the tag, restarted the server, etc., but I couldn't get 
> past the error page: 
> 
> 'custom_tags' is not a valid tag library: Template library custom_tags not 
> found, tried 
> django.templatetags.custom_tags,django.contrib.staticfiles.templatetags.custom_tags,django.contrib.admin.templatetags.custom_tags
> 
> Could someone please explain where to put my custom tags so that I will be 
> able to reuse them throughout the project?

You have not explained exactly where you put your "custom_tags" app. Check the 
following things:

o The custom_tags/ directory should be in the same directory as your manage.py
o Your template tag(s) should be in, say, 
custom_tags/templatetags/custom_tags.py
o There should be two empty files, custom_tags/__init__.py and 
custom_tags/template_tags/__init__.py
o Use "{% load custom_tags %}" where the "custom_tags" here refers to the file 
name, not the app name

I'm guessing you have most of this but are missing the __init__.py files.

hth

  - Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Defining custom template tags in a new app

2013-08-20 Thread Daniel Roseman
On Tuesday, 20 August 2013 11:53:27 UTC+1, kandelabr wrote:

> Hello!
>
> I want to define a new template tag and use it in a number of applications 
> inside my django project. The documentation says:
>
> *Custom template tags and filters must live inside a Django app. If they 
> relate to an existing app it makes sense to bundle them there; otherwise, 
> you should create a new app to hold them.
>
> *But I could not find a word in documentation on how to {% load %} tags 
> from another app. I added the new 'custom_tags' app it to INSTALLED_APPS, 
> registered, imported the tag, restarted the server, etc., but I couldn't 
> get past the error page: 
>
> *'custom_tags' is not a valid tag library: Template library custom_tags 
> not found, tried 
> django.templatetags.custom_tags,django.contrib.staticfiles.templatetags.custom_tags,django.contrib.admin.templatetags.custom_tags
> *
>
> Could someone please explain where to put my custom tags so that I will be 
> able to reuse them throughout the project?
>
> Thank you!
>

Django doesn't care what app the tags are in, as long as that app is in 
INSTALLED_APPS and the tags are in the templatetags directory inside the 
app (and Python requires a blank __init__.py in that directory too).
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Bulk-creating two ForeignKey linked models - id field for relationship isn't set properly?

2013-08-20 Thread Daniel Roseman
On Tuesday, 20 August 2013 12:10:34 UTC+1, Victor Hooi wrote:

> Hi,
>
> 1. Hmm, in that case, using bulk_create may not work - I'm currently 
> relying on generating the full lists of Products and ProductImages, then 
> saving in a batch at the end.
>
> So I need to loop through and call .save() individually on each Product, 
> then the corresponding ProductImages, before moving onto the next Product().
>
> Are there any workarounds for this, or any way I could still leverage on 
> bulk_create()?
>
>
Can you bulk save the Products first, then assign them to the ProductImages 
and bulk save those?
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Best-practice for "join mailing list" form on every page

2013-08-20 Thread Steven Smith
I've got a simple form with one field that appears in the footer of my 
site, asking users to enter their email address to subscribe to our mailing 
list.

Rather than duplicate the form-processing logic in every single view, what 
should I do?
- POST to one location, but use a context processor to add the form in GET 
contexts?
- Add a decorator to every view that does the form logic
- Some other third option?

What do people typically do in this type of situation?


Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


If type of a field could be DYNAMIC

2013-08-20 Thread Vlad Krab
Hi everyone, I`m trying to solve this problem for a really long time but 
can`t find a solution.
I write an app, the feature is to LET USER CHANGE FIELD`S TYPE. 
But I can not. My Django and Python knowlege are weak now, despite I`ve 
tried to find something like this a lot.

*Please, may you advice me something? At least, do you have any idea how 
could I manage with this?*
What I have now, is models describing a head-field (the amount of fields is 
dynamic too, head is like a head in table) and variants of potentional 
types. 
*Please, look at* 
http://stackoverflow.com/questions/18296566/django-dynamic-form-generation-changing-field-type
All I have is there.

I suppose, for this purpose I need a function, but nothing I wrote worked 
(my syntax knowlege is weak).

 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Defining custom template tags in a new app

2013-08-20 Thread kandelabr
Hello!

I want to define a new template tag and use it in a number of applications 
inside my django project. The documentation says:

*Custom template tags and filters must live inside a Django app. If they 
relate to an existing app it makes sense to bundle them there; otherwise, 
you should create a new app to hold them.

*But I could not find a word in documentation on how to {% load %} tags 
from another app. I added the new 'custom_tags' app it to INSTALLED_APPS, 
registered, imported the tag, restarted the server, etc., but I couldn't 
get past the error page: 

*'custom_tags' is not a valid tag library: Template library custom_tags not 
found, tried 
django.templatetags.custom_tags,django.contrib.staticfiles.templatetags.custom_tags,django.contrib.admin.templatetags.custom_tags
*

Could someone please explain where to put my custom tags so that I will be 
able to reuse them throughout the project?

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


Re: Is it possible to have 1-to-Many and 1-to-1 relationships for one specific table?

2013-08-20 Thread Daniel Roseman
On Tuesday, 20 August 2013 12:12:40 UTC+1, Pepsodent Cola wrote:

> Ok let's start from the very beginning because this MVC business is making 
> me juggle too many balls all at once.  More than I can handle and 
> understand.
>
>
> ### PART A.1
> With this Filter 5 view code I get the list result that I expect.  But it 
> is not ordered the way I want.
>
> class AltwordlistView(generic.DetailView):
> model = Word
> template_name = 'navi_polls/altword_list.html'
> context_object_name = 'poll'
>
> def get_queryset(self):
> # Filter 5
> return *Word.objects.filter(direct_transl_word='')*
> *
> *
> *
> *
> ### PART A.2 - *Detail page*
> Page
>
> Filter 5
> * Page - Leafy 2 = 18 votes
> * Page - Leafy 3 = 50 votes
>
>
>
> ### PART B.1
> So when I want to simulate and test different querys in Python shell then 
> I'm having trouble simulating the above query syntax.
> This is as far as I'm able to simulate Filter 5 in shell.  How can I 
> proceed further with this simulation?
>
> >>> from navi_polls.models import Word, Altword
> >>> 
> >>> Word.objects.filter(direct_transl_word='')
> [, , ]
> >>> 
> >>> p = Word.objects.get(pk=1)
> >>> p
> 
>
>
> ### PART B.2 - *Filter 5 simulation errors*
>
> >>> p
> 
> >>> 
> >>> p.Word.objects.filter(direct_transl_word='')
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'Word' object has no attribute 'Word'
> >>> 
> >>> 
> >>> 
> >>> p.objects.filter(direct_transl_word='')
> Traceback (most recent call last):
>   File "", line 1, in 
>   File 
> "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 
> 232, in __get__
> raise AttributeError("Manager isn't accessible via %s instances" % 
> type.__name__)
> AttributeError: Manager isn't accessible via Word instances
> >>> 
> >>> 
> >>> 
> >>> p.filter(direct_transl_word='')
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'Word' object has no attribute 'filter'
> >>> 
>
>

I can't see how any of this is related to your original question. That was 
to do with the Altword model, which you are not using in any of the code 
you have posted. What does it have to do with the issue of multiple 
relationships?

I also have no idea what all that code in B.2 is for. Why aren't you using 
the same code as your view? Why, after succesfully doing the filter, are 
you ignoring the result, then doing a .get() to get a single instance and 
trying to run non-existent methods on it instead of the queryset? 
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Is it possible to have 1-to-Many and 1-to-1 relationships for one specific table?

2013-08-20 Thread Pepsodent Cola
Ok let's start from the very beginning because this MVC business is making 
me juggle too many balls all at once.  More than I can handle and 
understand.


### PART A.1
With this Filter 5 view code I get the list result that I expect.  But it 
is not ordered the way I want.

class AltwordlistView(generic.DetailView):
model = Word
template_name = 'navi_polls/altword_list.html'
context_object_name = 'poll'

def get_queryset(self):
# Filter 5
return *Word.objects.filter(direct_transl_word='')*
*
*
*
*
### PART A.2 - *Detail page*
Page

Filter 5
* Page - Leafy 2 = 18 votes
* Page - Leafy 3 = 50 votes



### PART B.1
So when I want to simulate and test different querys in Python shell then 
I'm having trouble simulating the above query syntax.
This is as far as I'm able to simulate Filter 5 in shell.  How can I 
proceed further with this simulation?

>>> from navi_polls.models import Word, Altword
>>> 
>>> Word.objects.filter(direct_transl_word='')
[, , ]
>>> 
>>> p = Word.objects.get(pk=1)
>>> p



### PART B.2 - *Filter 5 simulation errors*

>>> p

>>> 
>>> p.Word.objects.filter(direct_transl_word='')
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'Word' object has no attribute 'Word'
>>> 
>>> 
>>> 
>>> p.objects.filter(direct_transl_word='')
Traceback (most recent call last):
  File "", line 1, in 
  File 
"/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 
232, in __get__
raise AttributeError("Manager isn't accessible via %s instances" % 
type.__name__)
AttributeError: Manager isn't accessible via Word instances
>>> 
>>> 
>>> 
>>> p.filter(direct_transl_word='')
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'Word' object has no attribute 'filter'
>>> 
















On Tuesday, August 20, 2013 12:30:54 PM UTC+2, Daniel Roseman wrote:
>
> On Tuesday, 20 August 2013 11:25:02 UTC+1, Pepsodent Cola wrote:
>
>>
>> But the above Detail list initially works by a 1-to-Many relationship. 
>>  When I add my 1-to-1 relationship in order to connect the votes field to 
>> Word table then I get a bunch of weird MVC conflicts that I don't 
>> understand.  So it makes me think that you cannot have 1-to-Many and 1-to-1 
>> in the same table (Altword), is that True or False?
>>
>
> That is *false*.
>
> But you need to *tell us what the problems are*. There's no point saying 
> "the database doesn't do what I wish for" or "I get weird conflicts". You 
> need to show exactly what is happening: what you tried, what you expected, 
> what you actually got, and post the actual error message and traceback.
> --
> DR.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Bulk-creating two ForeignKey linked models - id field for relationship isn't set properly?

2013-08-20 Thread Victor Hooi
Hi,

1. Hmm, in that case, using bulk_create may not work - I'm currently 
relying on generating the full lists of Products and ProductImages, then 
saving in a batch at the end.

So I need to loop through and call .save() individually on each Product, 
then the corresponding ProductImages, before moving onto the next Product().

Are there any workarounds for this, or any way I could still leverage on 
bulk_create()?

2. Cool, thanks for the tip - completely forgotten about this - enumerate() 
will be very useful =).

Cheers,
Victor

On Tuesday, 20 August 2013 20:40:52 UTC+10, Daniel Roseman wrote:
>
> On Tuesday, 20 August 2013 10:57:52 UTC+1, Victor Hooi wrote:
>
>> Hi,
>>
>> *1. Bulk Creating Products/ProductImages*
>>
>> I have a Django custom management command that bulk-loads a list of 
>> products and product images from a JSON file.
>>
>> I have a Product model, along with an ProductImage model - each Product 
>> may have many ProductImages.
>>
>> class Product(models.Model):
>>> ...
>>> name = models.CharField(max_length=200, help_text='Name of this 
>>> product.')
>>> description = models.TextField(help_text='Short description of this 
>>> product.')
>>> external_id = models.CharField(max_length=100, unique=True, 
>>> help_text='Unique identifier for this product provided by the supplier.')
>>> brand = models.ForeignKey(Brand)
>>> supplier = models.ForeignKey(Supplier)
>>> selling_price = models.DecimalField(max_digits=10, decimal_places=2, 
>>> help_text='The price which we\'re selling this product at.')
>>> original_price = models.DecimalField(max_digits=10, 
>>> decimal_places=2, help_text='The original retail price of this product, 
>>> before any discounts.')
>>> current_stock_level = models.PositiveIntegerField(default=0)
>>> current_sold_count = models.PositiveIntegerField(default=0)
>>> ...
>>
>>
>> class ProductImage(models.Model):
>>> product = models.ForeignKey(Product, related_name='images')
>>> image = models.ImageField(max_length=200, upload_to='product_images')
>>> # TODO - Do we actually want to make retina images a distinct column 
>>> in the database? May need to revisit this.
>>> retina_image = models.ImageField(max_length=200, 
>>> upload_to='product_images')
>>> size = models.ForeignKey(ImageSize)
>>> ordinal = models.PositiveIntegerField(default=0)
>>> class Meta:
>>> ordering = ['ordinal']
>>> unique_together = ('product', 'size', 'ordinal')
>>> def __unicode__(self):
>>> return u'%s image %i for %s' % (self.size, self.ordinal, 
>>> self.product.name)
>>
>>
>> I have a single look that iterates through the JSON file, creating a list 
>> of Products, as well as a list of ProductImages that link back to those 
>> products. (The below is an extract)
>>
>> products = []
>>> product_images = []
>>> ...
>>> for product in json_data:
>>> brand, created_new_brand = 
>>> Brand.objects.get_or_create(name=product['brand'])
>>> if created_new_brand:
>>> new_brands_created += 1
>>> ...
>>> current_product = Product(name = product['name'],
>>> brand = brand,
>>> supplier = supplier,
>>> description = 
>>> product['description'],
>>> ...
>>> )
>>> ...
>>> for image_set in product['images']:
>>> for size in image_sizes.keys():
>>> product_images.append(ProductImage(product = 
>>> current_product,
>>>image = 
>>> image_set[size],
>>>retina_image 
>>> = image_set[size],
>>>size = 
>>> image_sizes[size],
>>>ordinal = 
>>> image_set_counter,
>>>))
>>> image_set_counter += 1
>>> ...
>>> Product.objects.bulk_create(products)
>>> ...
>>> for product_image in product_images:
>>> product_image.save()
>>
>>
>> I then call bulk_create() on the products list, which succeeds.
>>
>> However, when I try to call .save() or bulk_create() on the ProductImage, 
>> they fail, saying that product_id is NULL.
>>
>> IntegrityError: null value in column "product_id" violates not-null 
>>> constraint
>>> DETAIL:  Failing row contains (8, null, 
>>> https://cdn.foobar.com.au/site_media/uploads/product_im..., 
>>> https://cdn.foobar.com.au/site_media/uploads/product_im..., 4, 0).
>>
>>
>> If I actually inspect one one of the items in the ProductImages list - 
>> product_image.product seems to point t

Re: Django signals to all connections?

2013-08-20 Thread Jani Tiainen
Hi,

Well it seems that you have understood things a bit incorrectly.

First at all, only logged in user is the one accessing some page (a view) from 
Django system.

After that there is nobody logged in traditional sense - there is no simple way 
to detect that user closed browser and was "logged out" nor there is no simple 
way to tell that who is actually even logged in. Most "logged in" counters do 
rely on "less than X time from last action" means active user, whether or not 
that is true.

So what you asked is not possible to do that way. 

That doesn't mean that you can't do it - it would just require a bit more work.

You need two things for that - first you need means to actually store message 
somewhere and secondly you need some mechanism that you check unread messages 
per user return messages in some proper format if there are unread messages and 
mark them read somehow.

That covers serverside work pretty well. Nothing magic just a bit of coding 
work.

In a client you have few options - as you asked for live update you would have 
to have (timed) piece of javascript that in certain intervals pulls messages 
(if any) from server.

There exists other techniques (server push, BOSH, Comet, websockets) as well 
but that is pretty much simplest one to implement.

If you're lucky you can find good examples by gooling for "django web chat" or 
similiar.

On Mon, 19 Aug 2013 06:48:33 -0700 (PDT)
Gerd Koetje  wrote:

> but can it also update a message on a page where that user is without 
> reloading the page?
> 
> lets say user 1 is on page http://www.domain.com/acertainview/
> 
> and at that moment i start a signal as admin with the text hello there
> Can i update the text on his page to that text (live)
> 
> 
> Op maandag 19 augustus 2013 06:29:45 UTC+2 schreef Gerd Koetje:
> >
> > Is is possible to start an event at all connected users with signals?
> > If this is possible can someone show me an example of it.
> >
> >
> > Greetz
> > Gerd
> >
> >
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Representing infinity or "no limit" in an integer field?

2013-08-20 Thread Simon Riggs
On 20 August 2013 11:46, Jani Tiainen  wrote:

> I think pretty latest PostgreSQL can use indexes to filter NULL values as 
> well (doesn't have facility to store them though).

Postgres can use an index to find NULL values, so SELECT * FROM foo
WHERE col IS NULL can be indexed.

Not sure what you mean by "doesn't have facility to store them". NULL
values are stored in the database, they just don't occupy the same
space as non-NULL values. PostgreSQL's support of NULL values is full
and complete, in line with SQL Standard requirements.

> MySQL uses table statistics to determine are NULL values indexed or not.

Postgres stats include number of values NULL.

-- 
 Simon Riggs   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Representing infinity or "no limit" in an integer field?

2013-08-20 Thread Jani Tiainen
On Mon, 19 Aug 2013 11:14:54 -0700 (PDT)
Jason Arnst-Goodrich  wrote:

> 
> >
> > Problem is that usually databases aren't very fast to search NULL values 
> > so if you have to for example produce often list of products that you can 
> > buy "infinite amount", you would like to consider using value(s) that don't 
> > conflict from valid set of values.
> 
> 
> I'm pretty sure that's not true.

My knowledge is limited per implementation but as far as I know, standard 
implementation is not to include NULL's (since NULL means "does not exist").

I think pretty latest PostgreSQL can use indexes to filter NULL values as well 
(doesn't have facility to store them though). Oracle since 11g has option to 
include null values in the index.

MySQL uses table statistics to determine are NULL values indexed or not.

For the rest I don't have knowledge about. 

That doesn't remove the fact that there will be a limit for ordering one time - 
though I would be happy to know what "unlimited" amount of ordering would mean 
and how to actually it would be implemented and what's the real world use 
case...

> +1 to store as Null. 
>
> On Monday, August 19, 2013 1:07:27 AM UTC-7, Jani Tiainen wrote:
> >
> > On Mon, 19 Aug 2013 00:39:09 -0700 (PDT) 
> > Victor Hooi > wrote: 
> >
> > > Hi, 
> > > 
> > > I have a Django IntegerField that I'm using to store the purchase limit 
> > for 
> > > a product. 
> > > 
> > > purchase_limit = models.IntegerField() 
> > > 
> > > 
> > > I also need to represent no limit (i.e. infinity) as well in that field. 
> > > 
> > > I was thinking of just using NULL to represent no limit. 
> > > 
> > > purchase_limit = models.IntegerField(blank=True, null=True) 
> > > 
> > > 
> > > Zero would have a meaning for this field (you can't buy any), however 
> > > negative numbers don't have any meaning. 
> > > 
> > > Hence, another option is just to use say, -1 as the value to represent 
> > no 
> > > limit. 
> > > 
> > > Any thoughts on either option, or which one is more "correct"? 
> >
> > From mathematical point integers forms an infinite (countable) set. Though 
> > in computer science interger is usually a finite set. So what you need is 
> > just define a logic. Note that this also makes impossible to enforce 
> > "unlimited" amount to buy so there will definitely be some maximum amount 
> > you can really buy. 
> >
> > NULL is usually interpreted as "no value defined" which would suit well in 
> > that sense. Problem is that usually databases aren't very fast to search 
> > NULL values so if you have to for example produce often list of products 
> > that you can buy "infinite amount", you would like to consider using 
> > value(s) that don't conflict from valid set of values. 
> >
> > I personally would pick max value while leaving NULL to mean "no value 
> > defined". 
> >
> > -- 
> >
> > Jani Tiainen 
> >
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Bulk-creating two ForeignKey linked models - id field for relationship isn't set properly?

2013-08-20 Thread Daniel Roseman
On Tuesday, 20 August 2013 10:57:52 UTC+1, Victor Hooi wrote:

> Hi,
>
> *1. Bulk Creating Products/ProductImages*
>
> I have a Django custom management command that bulk-loads a list of 
> products and product images from a JSON file.
>
> I have a Product model, along with an ProductImage model - each Product 
> may have many ProductImages.
>
> class Product(models.Model):
>> ...
>> name = models.CharField(max_length=200, help_text='Name of this 
>> product.')
>> description = models.TextField(help_text='Short description of this 
>> product.')
>> external_id = models.CharField(max_length=100, unique=True, 
>> help_text='Unique identifier for this product provided by the supplier.')
>> brand = models.ForeignKey(Brand)
>> supplier = models.ForeignKey(Supplier)
>> selling_price = models.DecimalField(max_digits=10, decimal_places=2, 
>> help_text='The price which we\'re selling this product at.')
>> original_price = models.DecimalField(max_digits=10, decimal_places=2, 
>> help_text='The original retail price of this product, before any 
>> discounts.')
>> current_stock_level = models.PositiveIntegerField(default=0)
>> current_sold_count = models.PositiveIntegerField(default=0)
>> ...
>
>
> class ProductImage(models.Model):
>> product = models.ForeignKey(Product, related_name='images')
>> image = models.ImageField(max_length=200, upload_to='product_images')
>> # TODO - Do we actually want to make retina images a distinct column 
>> in the database? May need to revisit this.
>> retina_image = models.ImageField(max_length=200, 
>> upload_to='product_images')
>> size = models.ForeignKey(ImageSize)
>> ordinal = models.PositiveIntegerField(default=0)
>> class Meta:
>> ordering = ['ordinal']
>> unique_together = ('product', 'size', 'ordinal')
>> def __unicode__(self):
>> return u'%s image %i for %s' % (self.size, self.ordinal, 
>> self.product.name)
>
>
> I have a single look that iterates through the JSON file, creating a list 
> of Products, as well as a list of ProductImages that link back to those 
> products. (The below is an extract)
>
> products = []
>> product_images = []
>> ...
>> for product in json_data:
>> brand, created_new_brand = 
>> Brand.objects.get_or_create(name=product['brand'])
>> if created_new_brand:
>> new_brands_created += 1
>> ...
>> current_product = Product(name = product['name'],
>> brand = brand,
>> supplier = supplier,
>> description = 
>> product['description'],
>> ...
>> )
>> ...
>> for image_set in product['images']:
>> for size in image_sizes.keys():
>> product_images.append(ProductImage(product = 
>> current_product,
>>image = 
>> image_set[size],
>>retina_image = 
>> image_set[size],
>>size = 
>> image_sizes[size],
>>ordinal = 
>> image_set_counter,
>>))
>> image_set_counter += 1
>> ...
>> Product.objects.bulk_create(products)
>> ...
>> for product_image in product_images:
>> product_image.save()
>
>
> I then call bulk_create() on the products list, which succeeds.
>
> However, when I try to call .save() or bulk_create() on the ProductImage, 
> they fail, saying that product_id is NULL.
>
> IntegrityError: null value in column "product_id" violates not-null 
>> constraint
>> DETAIL:  Failing row contains (8, null, 
>> https://cdn.foobar.com.au/site_media/uploads/product_im..., 
>> https://cdn.foobar.com.au/site_media/uploads/product_im..., 4, 0).
>
>
> If I actually inspect one one of the items in the ProductImages list - 
> product_image.product seems to point to a valid product, however, 
> product_image.product_id seems to be None:
>
> ipdb> p product_image.product
>> 
>> ipdb> p product_image.product_id
>> None
>
>
> This is strange, because if I manually create the same ProductImage from 
> the shell, the product_image.product_id field is populated.
>
> I'm guessing this product_id field should resolve to the pk id of the 
> product in product_image.product, right?
>
> However, in my case, when I instantiate each ProductImage and set it to a 
> Product, that actual Product hasn't been saved to the database - I'm 
> guessing that Product.id hasn't been generated yet, and the ProductImage 
> object I have is somehow broken?
>
> Is there another way I can achie

Re: Is it possible to have 1-to-Many and 1-to-1 relationships for one specific table?

2013-08-20 Thread Daniel Roseman
On Tuesday, 20 August 2013 11:25:02 UTC+1, Pepsodent Cola wrote:

>
> But the above Detail list initially works by a 1-to-Many relationship. 
>  When I add my 1-to-1 relationship in order to connect the votes field to 
> Word table then I get a bunch of weird MVC conflicts that I don't 
> understand.  So it makes me think that you cannot have 1-to-Many and 1-to-1 
> in the same table (Altword), is that True or False?
>

That is *false*.

But you need to *tell us what the problems are*. There's no point saying 
"the database doesn't do what I wish for" or "I get weird conflicts". You 
need to show exactly what is happening: what you tried, what you expected, 
what you actually got, and post the actual error message and traceback.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Is it possible to have 1-to-Many and 1-to-1 relationships for one specific table?

2013-08-20 Thread Pepsodent Cola
### PART A
My detail page looks like this in the web browser.
http://localhost:8000/navi_polls/specifics/1/

Page

Filter 5
* Page - Leafy 2 = 18 votes
* Page - Leafy 3 = 50 votes

My intended goal is to have Filter 5 sort this list with the highest votes 
down to the lowest votes.



### PART B
In order to do that somebody suggested to me a few weeks ago that I needed 
to create a relationship between the tables Word and Altword since the 
votes field is located in Altword table.

But the above Detail list initially works by a 1-to-Many relationship. 
 When I add my 1-to-1 relationship in order to connect the votes field to 
Word table then I get a bunch of weird MVC conflicts that I don't 
understand.  So it makes me think that you cannot have 1-to-Many and 1-to-1 
in the same table (Altword), is that True or False?

*Models*
#___

class Word(models.Model):
rosword = models.CharField(max_length=200)
direct_transl_word = models.CharField(max_length=120, blank=True, 
null=True)

def __unicode__(self):
return self.rosword
#___

class Altword(models.Model):
#rosword = models.ForeignKey(Word)
rosword = models.ForeignKey(Word, related_name='altword_rosword')
alt_ros_word = models.CharField(max_length=200)
wordy = models.OneToOneField(Word, related_name='wordy', 
primary_key=True)
votes = models.IntegerField(default=0)

def __unicode__(self):
return self.alt_ros_word
#___



*Views*
#___

class AltwordlistView(generic.DetailView):
model = Word
#model = Altword
template_name = 'navi_polls/altword_list.html'
context_object_name = 'poll'

def get_queryset(self):
*# Filter 5*
*return Word.objects.filter(direct_transl_word='')*
#return Word.objects.filter(direct_transl_word='')*.order_by('-votes') 
*  # Detail page doesn't order list.
#return Altword.objects.filter(rosword__direct_transl_word='')
#return Altword.objects.filter(word__direct_transl_word='')
#___













On Tuesday, August 20, 2013 3:53:09 AM UTC+2, Huu Da Tran wrote:
>
> On Monday, August 19, 2013 3:03:25 PM UTC-4, Pepsodent Cola wrote:
>
>> Is it possible to have 1-to-Many and 1-to-1 relationships for one 
>> specific table?
>> Because the database doesn't do what I wish for.
>>
>
> What is the intended goal?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Tech start up looking for a Python/Django rockstar - £300/day - fast start

2013-08-20 Thread Cal Leeming [Simplicity Media Ltd]
Hello all,

One of our tech startup clients in London is currently looking for an
experienced Python/Django rockstar.

The position is full time, salary is £300/day, working remotely or on-site,
shares are also being considered for those who can bring exceptional
talent/experience.

Currently in beta, this product is changing the way people eat by making it
easier to plan, order and cook great food.

After just recently finishing a 1-month hackathon to get the product live,
they secured additional alpha funding and need to expand their team.

The product can be seen here;
www.therecipekit.co.uk

Being a hardcore tech team, you will benefit from;

* Good architectural code design
* Clean code
* Efficient communication
* Sane development patterns
* Rapid prototyping (first beta release was finished within 2 weeks, and
re-written twice)
* Other experienced start-up developers to bounce with

Some example requirements include;

* Migration to a new payments provider
* Changes to checkout workflow
* CMS improvements
* Order system control (cancel orders, refund payments etc)
* Discount code abuse prevention
* Notifications system
* Customer lifecycle tracking

The systems we use are;

* Django
* SASS
* South
* devserver
* uWSGI
* Pipeline
* EC2
* CloudFlare
* New Relic
* GIT
* HipChat
* Trello
* Mandrill
* Percona MySQL
* Stripe
* Bootstrap
* jQuery
* Redis
* Celery

Interested? Send us an email and tell us;

* Github profile
* Linkedin profile
* Availability and location
* Example of your best Python code (github/pastebin etc)
* Why we should hire you

Thanks

Cal

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Bulk-creating two ForeignKey linked models - id field for relationship isn't set properly?

2013-08-20 Thread Victor Hooi
Hi,

*1. Bulk Creating Products/ProductImages*

I have a Django custom management command that bulk-loads a list of 
products and product images from a JSON file.

I have a Product model, along with an ProductImage model - each Product may 
have many ProductImages.

class Product(models.Model):
> ...
> name = models.CharField(max_length=200, help_text='Name of this 
> product.')
> description = models.TextField(help_text='Short description of this 
> product.')
> external_id = models.CharField(max_length=100, unique=True, 
> help_text='Unique identifier for this product provided by the supplier.')
> brand = models.ForeignKey(Brand)
> supplier = models.ForeignKey(Supplier)
> selling_price = models.DecimalField(max_digits=10, decimal_places=2, 
> help_text='The price which we\'re selling this product at.')
> original_price = models.DecimalField(max_digits=10, decimal_places=2, 
> help_text='The original retail price of this product, before any 
> discounts.')
> current_stock_level = models.PositiveIntegerField(default=0)
> current_sold_count = models.PositiveIntegerField(default=0)
> ...


class ProductImage(models.Model):
> product = models.ForeignKey(Product, related_name='images')
> image = models.ImageField(max_length=200, upload_to='product_images')
> # TODO - Do we actually want to make retina images a distinct column 
> in the database? May need to revisit this.
> retina_image = models.ImageField(max_length=200, 
> upload_to='product_images')
> size = models.ForeignKey(ImageSize)
> ordinal = models.PositiveIntegerField(default=0)
> class Meta:
> ordering = ['ordinal']
> unique_together = ('product', 'size', 'ordinal')
> def __unicode__(self):
> return u'%s image %i for %s' % (self.size, self.ordinal, 
> self.product.name)


I have a single look that iterates through the JSON file, creating a list 
of Products, as well as a list of ProductImages that link back to those 
products. (The below is an extract)

products = []
> product_images = []
> ...
> for product in json_data:
> brand, created_new_brand = 
> Brand.objects.get_or_create(name=product['brand'])
> if created_new_brand:
> new_brands_created += 1
> ...
> current_product = Product(name = product['name'],
> brand = brand,
> supplier = supplier,
> description = 
> product['description'],
> ...
> )
> ...
> for image_set in product['images']:
> for size in image_sizes.keys():
> product_images.append(ProductImage(product = 
> current_product,
>image = 
> image_set[size],
>retina_image = 
> image_set[size],
>size = 
> image_sizes[size],
>ordinal = 
> image_set_counter,
>))
> image_set_counter += 1
> ...
> Product.objects.bulk_create(products)
> ...
> for product_image in product_images:
> product_image.save()


I then call bulk_create() on the products list, which succeeds.

However, when I try to call .save() or bulk_create() on the ProductImage, 
they fail, saying that product_id is NULL.

IntegrityError: null value in column "product_id" violates not-null 
> constraint
> DETAIL:  Failing row contains (8, null, 
> https://cdn.foobar.com.au/site_media/uploads/product_im..., 
> https://cdn.foobar.com.au/site_media/uploads/product_im..., 4, 0).


If I actually inspect one one of the items in the ProductImages list - 
product_image.product seems to point to a valid product, however, 
product_image.product_id seems to be None:

ipdb> p product_image.product
> 
> ipdb> p product_image.product_id
> None


This is strange, because if I manually create the same ProductImage from 
the shell, the product_image.product_id field is populated.

I'm guessing this product_id field should resolve to the pk id of the 
product in product_image.product, right?

However, in my case, when I instantiate each ProductImage and set it to a 
Product, that actual Product hasn't been saved to the database - I'm 
guessing that Product.id hasn't been generated yet, and the ProductImage 
object I have is somehow broken?

Is there another way I can achieve this then? (Loop through file, creating 
a list of Products and ProductImages, then bulk_creating them?)

*2. Image Set Counter*

Also, second question - in the last code segment above, I have a 
image_set_counte