Re: I need help doing a linked lookup in admin

2013-04-29 Thread Richard E. Cooke
I'm getting closer!  

First I found this note in the Content Types docs that explains why what I 
was doing does NOT work:
https://docs.djangoproject.com/en/1.4/ref/contrib/contenttypes/#django.contrib.contenttypes.generic.GenericForeignKey

*Due to the way 
GenericForeignKeyis
 implemented, you cannot use such fields directly with filters (
filter() and exclude(), for example) via the database API.*


Then I found this sample code in the admin docs:
https://docs.djangoproject.com/en/1.4/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_foreignkey


That I adapted to this for my admin form:
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == "ship_to":
kwargs["queryset"] = 
StreetAddress.objects.filter(po__supplier__street_address__location="shipto")
return super(POAdmin, self).formfield_for_foreignkey(db_field, 
request, **kwargs)

Note that while this is my "PO" data model, I used the model belonging to 
the address data "StreetAddress".  This is because which model does the 
object.filter() is the one whose __unicode__ function is called to get a 
representation of each record found for the list selection dialogue.  Which 
means, for my PO database, it describes each address by its PO number 
(which are the same number) making it hard to tell the addresses apart!  By 
using the StreetAddress model, it uses its __unicode__ instead, which makes 
a mini-summary of each address.  Much clearer.


This is not a perfect solution though because when I try to SAVE an edited 
PO record I get an error:

MultipleObjectsReturned: get() returned more than one StreetAddress -- it 
returned 2! Lookup parameters were {'id': u'2'}


I'm going to go back to letting it list all "ship to" addresses for all 
companies until I figure out what this error even means!

Another problem is its listing both address choices with the same 
description.  Another mystery to ponder.


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




AttributeError: 'AlumniResponseFormFormSet' object has no attribute 'new_objects'

2013-04-29 Thread Brian Dant


I'm using the Django admin and trying to make some changes to a related 
object that is mapped as 
anInlineModelAdmin
 object. 
I'm trying to do this using the save_related(self, request, form, formsets, 
change)
 method 
that Django provides. When I try to save something, I get an error:

AttributeError: 'AlumniResponseFormFormSet' object has no attribute 
'new_objects'
Other Info:

1) I have two InlineModelAdmins
2) I'm not saving the AlumniResponseInline when this error occurs. I'm 
saving another InlineModelAdmin associated with the same parent model
3) Until I added the save_related() method, I wasn't having problems saving 
either InlineModelAdmin
4) This error is happening after all *my* code is executed in 
save_related(), so I don't have control over catching that exception

>From the documentation on 
>save_related()
:

The save_related method is given the HttpRequest, the parent ModelForm 
instance, the list of inline formsets and a boolean value based on whether 
the parent is being added or changed. Here you can do any pre- or post-save 
operations for objects related to the parent. Note that at this point the 
parent object and its form have already been saved.


Thanks for your time!  

Brian Dant

PS:  I crossed posted this from SO, where I wasn't getting much traction. 
 I realized that this is probably more of a Django Admin detail, so y'all 
might know better :D

 

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




Re: Blog writen by django?

2013-04-29 Thread gilberto dos santos alves
mezzanine is spetacular. thanks! ;>). and plug and run.

Em segunda-feira, 29 de abril de 2013 00h50min42s UTC-3, Russell 
Keith-Magee escreveu:
>
>
> Here's a site that lists a whole lot of options:
>
> https://www.djangopackages.com/grids/g/blogs/
>
> DjangoPackages is well worth bookmarking -- it's a good archive of Django 
> packages for a wide range of website features, not just blogs.
>
> Yours,
> Russ Magee %-)
>
> On Mon, Apr 29, 2013 at 11:22 AM, gilberto dos santos alves <
> gsa...@gmail.com > wrote:
>
>> please could you point some one because this url [1], and this url [2] 
>> have conceptual problems and not only mistype error.
>> while this i am update docs for url [1], but it shows very poor html 
>> display and models.
>>
>> url:: [1] 
>> http://www.djangorocks.com/tutorials/how-to-create-a-basic-blog-in-django/
>> url:: [2] http://lightbird.net/dbe/blog.html
>>
>> For all of us following tutorials on django home this sounds like people 
>> have others important things to do. but we need tutorials for all people 
>> that have method of learning things follow tutorials not guess tutorial!
>>
>> thanks for your time.
>>
>> Em sábado, 27 de abril de 2013 22h54min56s UTC-3, Shawn Milochik escreveu:
>>
>>> Do a Google search. There are thousands. 
>>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

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




Re: Little help needed writing models for star-ratings app

2013-04-29 Thread Shawn Milochik
I reiterate: Please read the ORM documentation. That will answer all of
your questions. Once you understand how to do queries in the ORM (and which
queries are easier than others) then you will know how to design your
models so that they'll be easy to work with. As you're reading, make notes
about how you can aggregate and search across tables/models.

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




Re: Little help needed writing models for star-ratings app

2013-04-29 Thread surya


On Monday, April 29, 2013 10:31:34 PM UTC+5:30, Shawn Milochik wrote:
>
> It looks like you're not looking for a "little help." You're looking for 
> someone to do the work for you. 
>
> You'll get the best help if you try something, get stuck, and explain what 
> you tried and what the error is.
>
> Here is the documentation for using the ORM. This is not a snarky response 
> -- I really hope you do read it and learn how to use Django's ORM, which is 
> what you need to answer your own questions.
>
> https://docs.djangoproject.com/en/1.5/ref/models/querysets/
>
> Read that, try some stuff, then ask specific questions when you have 
> problems. You'll get a lot of great help if you do that.
>

I am not sure but.. my concern is more about "relationships"

How should I be defining Rating model for

counting number of specific ratings it got
user who rated it.. 

probably, to log the user data

user = models.ForeignKey(User) would work

But counting number of specific ratings it got is the issue!!

Say there is a Book X. Its ratings are by default 0, 0
Now, as the users add ratings, its get added up to the default and its 
fine.. 

but how to know who added what ratings? and how many times he changed etc..

would a ManyToMany field with User and Rating would work?

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




Re: Newbie: trying to get an existing project running on a different machine

2013-04-29 Thread Shawn Milochik
Do you have piston installed in the virtualenv where you're trying to test
this?

Check for any "local settings" on the production server that it may be
using but which aren't available through the repository.

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




Re: Little help needed writing models for star-ratings app

2013-04-29 Thread Shawn Milochik
It looks like you're not looking for a "little help." You're looking for
someone to do the work for you.

You'll get the best help if you try something, get stuck, and explain what
you tried and what the error is.

Here is the documentation for using the ORM. This is not a snarky response
-- I really hope you do read it and learn how to use Django's ORM, which is
what you need to answer your own questions.

https://docs.djangoproject.com/en/1.5/ref/models/querysets/

Read that, try some stuff, then ask specific questions when you have
problems. You'll get a lot of great help if you do that.

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




Newbie: trying to get an existing project running on a different machine

2013-04-29 Thread Horst Jäger

Hi folks,

I'm a complete newbie to Django and I have to edit a few lines of code in an 
existing project.

Of course I can't to so on the production machine.

So I'm trying to migrate the existing project onto a new development server. 
Django is up and running there and I can create sample projects as described in 

https://docs.djangoproject.com/en/dev/intro/tutorial01/

. I have transferred the existing project onto the new development server. I 
can start it there, but when I try to have a look at its index page I get a 
runtime error:

  File 
"/opt/djangostack-1.4.5-0/apps/django/lib/python2.7/site-packages/django/contrib/admin/sites.py",
 line 107, in unregister
raise NotRegistered('The model %s is not registered' % model.__name__)
NotRegistered: The model Consumer is not registered

This error happens in admin.py . This file reads:

from django.contrib import admin

import piston.models

admin.site.unregister(piston.models.Consumer)
admin.site.unregister(piston.models.Nonce)
admin.site.unregister(piston.models.Resource)
admin.site.unregister(piston.models.Token)

Now I wonder where the unregistered module might have been registered. I have 
searched the whole project tree for the string "Consumer" using grep and this 
string only occurrs in the file I already mentioned.

Any help would be greately appreciated.

Thanks in andvance

Horst


--
Horst Jäger h.jae...@medienkonzepte.de
Medienkonzepte  http://www.medienkonzepte.de/
Schaafenstr. 25, 50676 Köln, Germany
Tel +49 221 93187015  / Fax +49 221 93187029

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




Little help needed writing models for star-ratings app

2013-04-29 Thread surya
Here is the story so far

class Rating(models.Model):
positive_rating = models.FloatField(default=0)
negative_rating = models.FloatField(default=0)

class Book(models.Model):
year_pub = models.IntegerField(max_length=4)
category = models.ForeignKey(Category)
rating = models.ForeignKey(Rating)
hash_id = models.CharField(max_length=64, null=True, blank=True)

There are few books. Each will be having 2 types of rating. +ve one and -ve 
one, 
The rating is done using "stars". If +ve rating is done, -ve field will be 
0 vice versa.

votes could be simple stored in this way

o = Book.objects.get(pk=1)
o.rating.positive_rating += 2.5
o.rating.save()

Here comes the actual trouble -->

1. How to count the number of ratings
2. How to know which user has voted
3. How to know whether the user has previously voted or not

Typically, how to attach this MyUser (example) model to the Rating Model?

Thanks

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




Access request object in a custom template tag

2013-04-29 Thread Ponytech
Hello,

I am currently writing a custom template tag and I need to access the 
request object within the tag code.
When using tag helpers (*simple_tag*, *inclusion_tag *and *assignment_tag*) 
you can register them with an additional takes_context=True parameter that 
makes the request object available.
But this does not work with the low level *tag* decorator:

@register.tag(takes_context=True)def mytag(parser, token):
   ...

raises the exception:  *tag() got an unexpected keyword argument 
'takes_context'*
*
*
2 questions :

- is there a reason why the tag decorator does accept the takes_context 
argument ?
- how can I access the template context with this decorator (and thus the 
request object) ?


Thanks a lot.

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




Re: handling IntegrityError: Duplicate entry in UserCreationForm

2013-04-29 Thread isachin
hey guys, got the solution:

for each field to validate, I wrote a validate function:

code snippet:

def clean_:
try:
UserProfile.objects.get(phone_num=self.cleaned_data[''])
except UserProfile.DoesNotExist:
return self.cleaned_data[""]
raise forms.ValidationError(("FIELD VALUE already exist"))



On Sat, Apr 27, 2013 at 6:41 PM, isachin  wrote:

> @ Kelly: thank you very much for pointing me to django's source code.
>
> Yes I got that validation done and applied the same code for validation.
> Below is the snippet :
>
>profile.serial_num = self.cleaned_data['phone_num']
> try:
> profile._default_manager.get(phone_num=profile.serial_num)
> except UserProfile.DoesNotExist:
> profile.serial_num = profile.phone_num
> raise forms.ValidationError("Phone number already exist")
>
> @ all
>
> Now the next problem is, similar snippet appears in
>
> */site-packages/django/contrib/auth/forms.py*
>
> throws an error in the template form itself, but my code only shows up
> error in django's traceback, how can I bring it to front ?
> so that as soon as one fills phone number field it and press *submit, *it
> should say 'Phone number already exist'.
>
> m I doing wrong in using UserCreationForm ? or UserProfile. I m using
> user.get_profile() for profile fields.
>
>
>
> On Thu, Apr 25, 2013 at 7:09 PM, Kelly Nicholes wrote:
>
>> If you ever want to know how the UserCreationForm works, the source is
>> always available not only on your machine but also on
>> https://github.com/django/django/blob/master/django/contrib/auth/models.py
>>
>>
>> On Wednesday, April 24, 2013 9:27:39 AM UTC-6, sachin wrote:
>>>
>>> Hello,
>>>
>>> I m extending my auth user model to add addition entries like phone
>>> numbers and emp_id. In the model I m marking both the fields as unique=True.
>>> Form generation is using UserCreationForm. But whenever I try to save
>>> same phone number or emp_id it throws
>>>
>>> *IntegrityError: (1062, "Duplicate entry '447' for key 'phone_num'")*
>>>
>>> How to handle this error and show it to user during form input?
>>>
>>> Also how do the same UserCreationForm validates duplicate entry for
>>> username etc ??
>>>
>>>  --
>> 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/EaYF9DEptLo/unsubscribe?hl=en
>> .
>> 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?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
>
>
> --
> Sachin
>



-- 
Sachin

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




Re: Store arbitrary key-value pairs in model?

2013-04-29 Thread Branko Majic
On Mon, 29 Apr 2013 05:58:44 -0700 (PDT)
Victor Hooi  wrote:

> Hi,
> 
> I have a Django application that will need to store arbitraty
> 
> Basically, there are a series of "job scripts" that are submitted by
> users and then run.
> 
> Each of these jobs scripts may have an arbitrary number of key-value
> pairs attached to them (for example, output directory, or search
> term, or email address etc.).
> 
> There variables are then used by each script. The set of variables
> varies for each job script.
> 
> Is there an easy way to model this within Django?
> 
> We could store a serialised dict as a blob, but that sounds rather
> hackish.
> 
> I was thinking a document database (e.g. MongoDB, or Couch DB) might
> be more suitable, however, I'd like to keep it within Django, if
> possible (Django and relational DBs are widely used where I am, and
> there's good support for them).
> 
> Cheers,
> Victor
> 

Well, how about something like having model with fields (job_id, param,
value)? You may need to squeeze-in an ordinal in there as well -
(job_id, position, param, value).

Best regards

-- 
Branko Majic
Jabber: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
Џабер: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.


signature.asc
Description: PGP signature


Re: Using Django and R in a production environment?

2013-04-29 Thread Javier Guerra Giraldez
On Mon, Apr 29, 2013 at 2:13 AM, Derek  wrote:
> hat no one is actually using R in a production environment themselves (which
> is a little surprising to me).


well R itself is widely used in production... but the intersection
with Django is very small.  (after all, if you write your own R
analysis routines, why have them run in a web system)

--
Javier

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




Re: quick problem with str and int

2013-04-29 Thread MikeKJ
I did try that against just the string and got the same error hence the 
cast to int attempt, when cast to int I am using
(r'^json/(?P\d+)/$', '/views/json'),


>

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




Re: Upload csv with utf-8

2013-04-29 Thread Felipe Prenholato
Take a look, can help: https://github.com/chronossc/django-data-importer

Felipe 'chronos' Prenholato.
Linux User nº 405489
Home page: http://devwithpassion.com | http://chronosbox.org/blog
GitHub: http://github.com/chronossc/ | Twitter: http://twitter.com/chronossc


2013/4/29 Hélio Miranda 

> I managed to solve the problem like this:
> rep.GenreType line = ["IdGenre."] decode ("iso-8859-1")
>
> thank you
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

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




Re: quick problem with str and int

2013-04-29 Thread MikeKJ

Good idea so:  

In the model added

def get_json_reference(self):
return "/json/%i/" % int(self.reference)

called   which does produce the 
correct url for all in the for loop but still get 
Exception Type: TypeError at /json/810044/
Exception Value: 'str' object is not callable

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




Re: quick problem with str and int

2013-04-29 Thread Shawn Milochik
How about adding a get_absolute_url method to your model? Then you can take
care of the logic there, instead of the template.

https://docs.djangoproject.com/en/1.5/ref/models/instances/#get-absolute-url

Worst-case, you can just do the conversion in your view and assign it as a
new property to your model. Since it's just a Python class instance, you
can do my_obj.temp_url = (whatever) and then your template can access
my_obj.temp_url.

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




Re: quick problem with str and int

2013-04-29 Thread Addy Yeow
You would want to match this, (?P.*),  against a string not
integer.


On Mon, Apr 29, 2013 at 11:40 PM, MikeKJ  wrote:

> So unfortunately due to historical reason a numerical reference is set as
> a CharField in the model now I want to pass that reference through a url to
> json serialise something so
>
> 
> but I still get
>
> Exception Type: TypeError at /json/810044/
> Exception Value: 'str' object is not callable
>
> the url line is
>
> (r'^json/(?P.*)/$', '/views/json'),
>
> I am not entirely sure where it is complaining about str being uncallable
> but having cast it to int in the a href in the template  surely it should
> have resolved?  Any clues please?
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

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




quick problem with str and int

2013-04-29 Thread MikeKJ
So unfortunately due to historical reason a numerical reference is set as a 
CharField in the model now I want to pass that reference through a url to 
json serialise something so

.*)/$', '/views/json'),

I am not entirely sure where it is complaining about str being uncallable 
but having cast it to int in the a href in the template  surely it should 
have resolved?  Any clues please?

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




Re: Store arbitrary key-value pairs in model?

2013-04-29 Thread Shawn Milochik
A Django app sometimes benefits from a "No-SQL" database on the side. You
could do what you want using a text field and storing JSON or a pickled
value, but I advise against it. It's hard to query and de-duplicate.

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




Store arbitrary key-value pairs in model?

2013-04-29 Thread Victor Hooi
Hi,

I have a Django application that will need to store arbitraty

Basically, there are a series of "job scripts" that are submitted by users 
and then run.

Each of these jobs scripts may have an arbitrary number of key-value pairs 
attached to them (for example, output directory, or search term, or email 
address etc.).

There variables are then used by each script. The set of variables varies 
for each job script.

Is there an easy way to model this within Django?

We could store a serialised dict as a blob, but that sounds rather hackish.

I was thinking a document database (e.g. MongoDB, or Couch DB) might be 
more suitable, however, I'd like to keep it within Django, if possible 
(Django and relational DBs are widely used where I am, and there's good 
support for them).

Cheers,
Victor

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




Re: Upload csv with utf-8

2013-04-29 Thread Hélio Miranda
I managed to solve the problem like this:
rep.GenreType line = ["IdGenre."] decode ("iso-8859-1")

thank you

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




Re: django-filetransfers and HttpResponseRedirect

2013-04-29 Thread Venkatraman S
On Mon, Apr 29, 2013 at 3:43 PM, Shawn Milochik  wrote:

> Use HttpResponseRedirect, as you mention in your subject line.
>

Question is 'why'?

-V

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




Re: Upload csv with utf-8

2013-04-29 Thread Hélio Miranda
The content of my csv is not in utf-8
That's why I want, when I upload the csv and introduce the data and insert 
it in db utf-8, but do not know how to do this in my code that I put at the 
beginning

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




Re: Upload csv with utf-8

2013-04-29 Thread Tom Evans
On Mon, Apr 29, 2013 at 12:43 PM, Hélio Miranda  wrote:
> in my code was trying to do this
>   rep.GenreType line = ["IdGenre."] decode ("utf-8")
>
> but it gives me the following error:
> 'utf8' codec can not decode byte 0xE9 in position 3: invalid continuation
> byte
>
> Unicode error hint
>
> The string That Could not be encoded / decoded was: Com�dia
>

I doubt your content is UTF-8 encoded (because of the contents of the
error message) - try latin1 instead of UTF-8.

Cheers

Tom

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




Re: Upload csv with utf-8

2013-04-29 Thread Hélio Miranda
in my code was trying to do this
  rep.GenreType line = ["IdGenre."] decode ("utf-8")

but it gives me the following error:
'utf8' codec can not decode byte 0xE9 in position 3: invalid continuation 
byte

Unicode error hint

The string That Could not be encoded / decoded was: *Com�dia*

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




Re: Upload csv with utf-8

2013-04-29 Thread Hélio Miranda
The error I get is this.
I can not enter words with accents

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




Unefficient SQL query while excluding results on QuerySet

2013-04-29 Thread Michael Elovskikh


Hello, I'm trying to figure up if I've found a bug and if anyone has 
already solved a similar problem:
I've got two basic models (I've simplified them to make it easier to 
understand):

class A(models.Model):
pass
class B(models.Model):
name = models.CharField(max_length=15)
a = models.ForeignKey(A)


Now I want to select rows from table a that are refered from table b that 
dont have some value in collumn name.
Here is sample SQL I expect Django ORM to produce:

SELECT * FROM nonefficient_foreign_key_exclude_a aINNER JOIN 
nonefficient_foreign_key_exclude_b b ON a.id = b.a_idWHERE NOT (b.name = '123');

In case of filter() method of django.db.models.query.QuerySet it works as 
expected:

>>> from nonefficient_foreign_key_exclude.models import A>>> print 
>>> A.objects.filter(b__name='123').querySELECT 
>>> `nonefficient_foreign_key_exclude_a`.`id` FROM 
>>> `nonefficient_foreign_key_exclude_a` INNER JOIN 
>>> `nonefficient_foreign_key_exclude_b` ON 
>>> (`nonefficient_foreign_key_exclude_a`.`id` = 
>>> `nonefficient_foreign_key_exclude_b`.`a_id`) WHERE 
>>> `nonefficient_foreign_key_exclude_b`.`name` = 123

But if I use exclude() method (a negative form of Q object in underlaying 
logic) it creates a really strange SQL query:

>>> print A.objects.exclude(b__name='123').querySELECT 
>>> `nonefficient_foreign_key_exclude_a`.`id` FROM 
>>> `nonefficient_foreign_key_exclude_a` WHERE NOT 
>>> ((`nonefficient_foreign_key_exclude_a`.`id` IN (SELECT U1.`a_id` FROM 
>>> `nonefficient_foreign_key_exclude_b` U1 WHERE (U1.`name` = 123  AND 
>>> U1.`a_id` IS NOT NULL)) AND `nonefficient_foreign_key_exclude_a`.`id` IS 
>>> NOT NULL))

Does anyone knows why ORM makes a subquery instead of just JOIN?

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




Re: Upload csv with utf-8

2013-04-29 Thread Andrew Boltachev
And if you get an error, can you post complete traceback?


2013/4/29 Hélio Miranda 

> continued without realizing how in my code I can do this ...
>
> The error I get is this
> strings in documents must be valid UTF-8
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

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




Re: Upload csv with utf-8

2013-04-29 Thread Hélio Miranda
continued without realizing how in my code I can do this ...

The error I get is this
strings in documents must be valid UTF-8

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




Re: django-filetransfers and HttpResponseRedirect

2013-04-29 Thread Shawn Milochik
Use HttpResponseRedirect, as you mention in your subject line.

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




Re: Upload csv with utf-8

2013-04-29 Thread Andrew Boltachev
Hi! Check this out https://gist.github.com/eightysteele/1174811

In short, value.decode('utf-8') must be used to prepare value, that was
read from file, encoded with utf-8 for processing.


2013/4/29 Hélio Miranda 

> I have a problem that is to read the csv file that contain words with
> accents.
> I have the following code in my application, but do not know how by
> working with utf-8.
> Someone can help me?
>
> Código (Python):
> def csv_upload(request):
> if request.method == 'POST':
>
> gen = Genre.objects.all()
> genres = dict(Genre.objects.all().values_list('GenreType',
> 'id'))
>
> for obj in gen:
> genres[obj.GenreType] = obj.id
>
> file = csv.DictReader(request.FILES['file'], delimiter=',',
>  quotechar='"')
>
> for line in file:
> report = Movie()
>
> if not line["IdGenre"] in genres:
> rep = Genre()
> rep.GenreType = line["IdGenre"]
> rep.save()
> genres[rep.GenreType] = rep.id;
>
> report.MovieTitle = line["MovieTitle"]
> report.MovieDuration = line["MovieDuration"]
> report.save()
>
> else:
> report.MovieTitle = line["MovieTitle"]
> report.MovieDuration = line["MovieDuration"]
> report.save()
> return render_to_response('index.html', {},
>   context_instance
> =RequestContext(request))
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

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




Deployment best practices - reasons?

2013-04-29 Thread Victor Hooi
Hi,

I'm currently looking at tidying up deployment for a Django app we use 
internally.

There's a couple of things that I know are best-practices, or it's just how 
I normally deploy Django apps, but I need to come up with strong cases for 
all of them. As in any organisation, if it ain't broke, don't fix it - so 
there needs to be a compelling argument from me to put them in place.

For example:

Why use Gunicorn? (versus just Apache)
Gunicorn is lightweight, uses less memory, and is easier to configure. 
Anything else?

Why use Apache/Nginx in front of Gunicorn? (versus just hitting Gunicorn on 
it's own)
Gunicorn isn't designed to be front-facing - so for example, it doesn't 
handle slow clients well. Ideally you'd want something like Nginx or Apache 
to buffer requests. Anything else?

Why use Supervisord (versus just init.d scripts with say ./manage.py 
run_gunicorn in there)?
Supervisord will restart crashed processes. Anything else?

Why use Sentry?
Allows easier viewing of errors. Anything else?

Cheers,
Victor

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




Upload csv with utf-8

2013-04-29 Thread Hélio Miranda
I have a problem that is to read the csv file that contain words with 
accents.
I have the following code in my application, but do not know how by working 
with utf-8.
Someone can help me?

Código (Python):
def csv_upload(request):
if request.method == 'POST':

gen = Genre.objects.all()
genres = dict(Genre.objects.all().values_list('GenreType', 'id'
))
   
for obj in gen:
genres[obj.GenreType] = obj.id
   
file = csv.DictReader(request.FILES['file'], delimiter=',',
 quotechar='"')

for line in file:  
report = Movie()
   
if not line["IdGenre"] in genres:
rep = Genre()
rep.GenreType = line["IdGenre"]
rep.save()
genres[rep.GenreType] = rep.id;
   
report.MovieTitle = line["MovieTitle"]
report.MovieDuration = line["MovieDuration"]
report.save()
   
else:
report.MovieTitle = line["MovieTitle"]
report.MovieDuration = line["MovieDuration"]
report.save()
return render_to_response('index.html', {},
  context_instance=
RequestContext(request))

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




Re: [django_tables2] Expected table or queryset, not 'str'.

2013-04-29 Thread Binith Babu
You were correct, it was indeed a version problem.
I was using latest django-tables2 in my new python virtual env and I had an 
older version (of django-tables2) installed as default, and the PYTHONPATH 
environment variable was pointing to the older version.

Problem solved, thanks for the time

thanks
-binith

On Friday, 26 April 2013 07:25:35 UTC-7, Binith Babu wrote:
>
> I am sorry I coud not find a solution in this thread
>
> Did you mean I am using an older version of django tables2 ?
> In that case I am not, I am using the latest version installed with pip.
> May be its my mistake, I am still trying to figure whether I am doing 
> something wrong.
> WIll post back if I find something.
>
> Thanks
> binith
>
>
>
> On Friday, 26 April 2013 06:53:06 UTC-7, Tom Evans wrote:
>>
>> On Fri, Apr 26, 2013 at 2:30 PM, Binith Babu  wrote: 
>> > 
>> > I got the same error today, anybody know a solution? 
>> > 
>>
>> Apart from the solution I already posted to the list in this thread? 
>>
>> Cheers 
>>
>> Tom 
>>
>

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




Re: Using Django and R in a production environment?

2013-04-29 Thread Derek
Again, thanks!

But it still seems that no one is actually using R in a production 
environment themselves (which is a little surprising to me).

On Wednesday, 24 April 2013 19:52:19 UTC+2, Alex wrote:
>
> There is another large potential gotcha, R is very memory heavy. 
> I do think the route of using Celery or other job management tools makes 
> sense, especially if you can use R across multiple backend machines. 
> Would celery mean one rpy2 per celery? You don't really want all your 
> users using the same R session anyways. 
>
> Thanks, 
> Alex 
>
> On 04/23/2013 11:08 PM, Derek wrote: 
> > Thanks Per-Olof 
> > 
> > No, it has more to do with the issue raised here: 
> > 
> https://github.com/Sleepingwell/DjangoRpyDemo/blob/master/README.md#django-configuration
>  
> > 
> > Possibly Celery could solve that (?) but I really would like to hear 
> from 
> > someone who actually has a production configuration set up and working. 
> > Perhaps there are less people in the sciences using Django than I 
> thought... 
> > 
> > Derek 
> > 
> > On Tuesday, 23 April 2013 21:32:12 UTC+2, Per-Olof �strand wrote: 
> >> 
> >> I am not sure I understand your question, but is it really related to 
> >> using specifically R? Could it be any kind of heavy number-crunching 
> that 
> >> needs to be done in the background by a scheduler/task manager? In that 
> >> case, django-celery may be an option: 
> >> http://docs.celeryproject.org/en/latest/index.html 
> >> 
> >> Per-Olof 
> >> 
> >> On Monday, April 22, 2013 9:26:05 PM UTC+2, Derek wrote: 
> >>> 
> >>> Based on googling around this topic, it seems that using RPy2 is the 
> most 
> >>> common way to interface with R from Python.  However all the 
> discussions on 
> >>> this seem to centre around working in a desktop (single user) 
> environment. 
> >>> 
> >>> The one discussion I could find that deals with the issue of working 
> with 
> >>> R "at scale" is this one - 
> >>> 
> https://github.com/Sleepingwell/DjangoRpyDemo/blob/master/README.md#django-configuration
>  
> >>> - which indicates problems with this approach; and suggests it might 
> be 
> >>> able to be overcome via creating distinct processes dedicated to run a 
> WSGI 
> >>> application (although this article does not give any steps on how to 
> do 
> >>> this, or whether it would work in practice). 
> >>> 
> >>> Another approach seems to be to use RPy2, with Twisted to enable 
> multiple 
> >>> sessions: 
> >>> 
> https://docs.google.com/presentation/d/11LJxej6jnbYKzJftpDudYFfVKjaB0BhOzrBSKaxJ2ME/edit#slide=id.p
>  
> >>> . 
> >>> 
> >>> Yet another approach might be to use Rserve ( 
> >>> http://www.rforge.net/Rserve/) and PyRserve ( 
> >>> http://pythonhosted.org/pyRserve/manual.html), but the latter seems 
> to 
> >>> currently be in beta. 
> >>> 
> >>> Question is: does anyone have any practical experience actually using 
> >>> Django with R in a production environment (i.e dozens or hundreds of 
> users 
> >>> doing high volume number crunching)? 
> >>> 
> >>> Thanks 
> >>> Derek 
> >>> 
> >>> PS Yes, we do need R and not one of the Python-based alternatives, as 
> R 
> >>> offers many routines simply not available in those as yet (also, the 
> client 
> >>> needs to re-use, and create new, R scripts themselves) 
> >>> 
> >> 
> > 
>
>

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