Strange unit test / OAuth Issue

2010-09-07 Thread Chris
So I wrote some django unit tests for an app that uses OAuth and I ran
into this strange issue when attempting to set my verifier:

On my local dev machine it likes me to set my verifier like so:
token.set_verifier(verifier)

On my production machine it like me to set my verifier like so:
oauth_request = oauth.OAuthRequest.from_consumer_and_token(
self.apicall.consumer,
token=token,
verifier=verifier,
http_url=self.apicall.access_token_url
)

Both my dev machine and production machine can't agree on which way
they would like to set the verifier. If I perform both methods, then
both dev and production seem to be happy!  Why is this? Could I have a
slightly different version of oauth on both the machines?

Here is the full snippet of code that sets the verifier and makes the
access token request:

verifier = "zNd4KsqnL9"
   # Dev likes it this way
token.set_verifier(verifier)

oauth_request = oauth.OAuthRequest.from_consumer_and_token(
self.apicall.consumer,
token=token,
# prod likes it this way
verifier=verifier,
http_url=self.apicall.access_token_url
)
oauth_request.sign_request(self.apicall.signature_method,
self.apicall.consumer, token
)
params = oauth_request.parameters
response = self.client.get(self.apicall.access_token_url,
params)

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



Re: Strange unit test / OAuth Issue

2010-09-09 Thread Chris
Awh yes thank you for the tip.

After removing the incorrect versions and installing the correct ones,
I ran a simple md5 checksum to make sure that both my local dev and
prod versions match:

from oauth import oauth
from md5 import md5
print "You are using version: ", oauth.VERSION
filename = oauth.__file__[:-1]
print "Your OAuth file is located here: ", filename
checksum = md5(open(filename, "rb").read()).hexdigest()
print "Your OAuth checksum is: ", checksum


On Sep 7, 1:39 pm, Bill Freeman  wrote:
> Why not check which version of oauth you have in each place?
>
> Even if there isn't a usable version indicator in the library, you could
> generate a file containing the chacksums of all the py files, sort it, and
> compare it.
>
> On Tue, Sep 7, 2010 at 4:46 AM, Chris  wrote:
> > So I wrote some django unit tests for an app that uses OAuth and I ran
> > into this strange issue when attempting to set my verifier:
>
> > On my local dev machine it likes me to set my verifier like so:
> > token.set_verifier(verifier)
>
> > On my production machine it like me to set my verifier like so:
> > oauth_request = oauth.OAuthRequest.from_consumer_and_token(
> >    self.apicall.consumer,
> >    token=token,
> >    verifier=verifier,
> >    http_url=self.apicall.access_token_url
> > )
>
> > Both my dev machine and production machine can't agree on which way
> > they would like to set the verifier. If I perform both methods, then
> > both dev and production seem to be happy!  Why is this? Could I have a
> > slightly different version of oauth on both the machines?
>
> > Here is the full snippet of code that sets the verifier and makes the
> > access token request:
>
> >        verifier = "zNd4KsqnL9"
> >       # Dev likes it this way
> >        token.set_verifier(verifier)
>
> >        oauth_request = oauth.OAuthRequest.from_consumer_and_token(
> >            self.apicall.consumer,
> >            token=token,
> >            # prod likes it this way
> >            verifier=verifier,
> >            http_url=self.apicall.access_token_url
> >        )
> >        oauth_request.sign_request(self.apicall.signature_method,
> >            self.apicall.consumer, token
> >        )
> >        params = oauth_request.parameters
> >        response = self.client.get(self.apicall.access_token_url,
> > params)
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

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



Easy database modeling question

2010-01-20 Thread Chris
This is my first Django experience and I'm having trouble figuring out
the right answer to the right relationship to have. (brain fart
maybe.. )
I have a site that users have profiles and can message each other. So
my model looks like:

class User(models.Model):
username = models.CharField(max_length=50)
password = models.CharField(max_length=50)
profile = models.ForeignKey(Profile)

class Profile(models.Model):
username = models.CharField(max_length=50, primary_key=True)
sex = models.CharField(max_length=50)
location = models.CharField(max_length=100)


class Messages(models.Model):
sender = models.CharField(max_length=100)
to = models.CharField(max_length=100)
subject = models.CharField(max_length=100)
message = models.TextField()
date = models.DateTimeField()

My question here is this a one-to-many relationship from Profile to
Messages? In that each profile has many messages or is it many-to-many
as each message has a sender and a recipient. Ultimately I want to be
able to easily pull the profile for the sender and recipient from the
message and from the User show their messages.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Storing API Passwords

2010-03-01 Thread Chris
Hello,

When working with photo API's such as twitpic, what is the best way of
storing the password?
Since the password needs to be sent in its natural form, hashing is
not an option. I read recently heard that a company was held
accountable (sued) for not encrypting their user's API passwords and
would rather be safe than sorry. I haven't been able to find an
effective way of doing so. Also I am using Postgres as my DB.

Any suggestions?

Thanks in advance.

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



How to launch home page from urls.py?

2010-10-13 Thread Chris
Hello,

Currently in my urls.py I have "( r'^winapp/(?P.*)$',
'django.views.static.serve', { 'document_root': 'winapp' } )," and I
can launch my home pahe by pointing my browser to something like
"a.b.com/winapp/HomePage.html".

I have gone through the documentation and a couple of books, but I
cannot figure out how to launch "HomePage.html" by using just
"a.b.com".

Any help is highly appreciated!

Thank you,
Chris

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



Issue uploading photos through the admin. PIL issue.

2010-11-22 Thread Chris
I am having an issue with uploading photos through the admin. I get
this error: "Upload a valid image. The file you uploaded was either
not an image or a corrupted image."  I am using ubuntu 10.04, python
26, virtualenv, and and pip. Is there a known issue with installng pil
through pip + virtualenv?

Any Ideas?

Thanks in advance!

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



Re: Issue uploading photos through the admin. PIL issue.

2010-11-22 Thread Chris
Opps, Just solved my own question.

python-dev is required which I had installed.

I found a package called pillow which seems to take care of the issue
that I was having.



On Nov 22, 2:07 pm, Chris  wrote:
> I am having an issue with uploading photos through the admin. I get
> this error: "Upload a valid image. The file you uploaded was either
> not an image or a corrupted image."  I am using ubuntu 10.04, python
> 26, virtualenv, and and pip. Is there a known issue with installng pil
> through pip + virtualenv?
>
> Any Ideas?
>
> Thanks in advance!

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



Re: Weird problem after schema change

2010-11-30 Thread chris
Nope, haven't defined anything interesting for admin. The field name
matches, as far as I know.

Frankly, though, given the length of time it takes for the server to
reply (owing to the huge number of entries for the m2m field), I guess
this really isn't worth fixing if it's more involved than a simple
check. Ah well.

Thanks,
Chris

On Nov 25, 7:07 pm, Venkatraman S  wrote:
> On Fri, Nov 26, 2010 at 6:30 AM, Chris Tandiono 
> wrote:
>
> > How can I get the date field to show up in the admin interface?
>
> Couple of checks:
> - have you defined any custom forms for admin?
> - Do the field names match properly?
>
> A good practice generally is : do a 'sqlall' before you make the change in
> your models.py and then again do the same after mod'ing your models.py file.
> Do a diff between the two output sqlall files.
>
> $python manage.py sqlall > before.txt
> $vim ...models.py
> $python manage.py sqlall > after.txt
>
> -V-

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



Re: empty DateTimeField?

2011-01-11 Thread chris
As Justin mentioned,  my guess is that you would have to manually
update the table definition to allow nulls for that column.

On Jan 11, 7:21 pm, galago  wrote:
> I tried but I get:
> Exception Type: IntegrityError Exception Value:
>
> (1048, "Column 'publish_date' cannot be null")
>
> Exception Location: C:\Python27\lib\site-packages\MySQLdb\connections.py in
> defaulterrorhandler, line 36
>
> Field definition: publish_date = models.DateTimeField(editable=False,
> blank=True, null=True)

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



How to display value from a sub model in the template

2011-02-20 Thread Chris
Hi !
 I have template page I'm trying to list all the player of a team, The
player model have 2 sub-model: playerVital and playerSkill.
The model playerVital has a one to one relation ship with the player
model and player skill have a foreign key to the player model.
 How can I show the value of the sub model when looping players in the
team object?
Showing value of the player model work fine but not the sub model.
I tried various syntax but nothing seem to work.

Thanks,
Chris

Here are the model and the template i'm building :
model.py
class Team(models.Model):
team_name = models.CharField(max_length=200)
def __unicode__(self):
return self.team_name

class Player(models.Model):
teamKey = models.ForeignKey(Team, blank=True, null=True)
first_name = models.CharField(max_length=200)
last_name = models.CharField(max_length=200)
def fullname(self):
return u'%s %s' % (self.first_name, self.last_name)
def __unicode__(self):
return self.fullname()

class PlayerVital(models.Model):
playerKey = models.OneToOneField(Player, primary_key=True)
position=models.CharField(max_length=2, choices=POSITION) #C/RW/LW/
D/G
hand= models.CharField(max_length=10, choices=HAND) #Left/Right
height= models.IntegerField()
weight= models.IntegerField()
nationality = models.CharField(max_length=200)


class PlayerSkills(models.Model):
SKILL_RANGE = zip( range(0,100), range(0,100))
playerKey = models.ForeignKey(Player)
skill_at_date = models.DateField('skill_date')
speed=models.IntegerField(default=50, choices=SKILL_RANGE,
blank=True)
strength=models.IntegerField(default=50, choices=SKILL_RANGE,
blank=True)
endurance=models.IntegerField(default=50, choices=SKILL_RANGE,
blank=True)

template :
{{ object.team_name }}

{% if error_message %}{{ error_message }}{%
endif %}

{% csrf_token %}



Player Name


Position


speed


height


{% for player in object.player_set.all %}


{{ player.fullname }}  


{{ player.playerVitals.position }} 

 
{{ player.playerSkill.speed }}


{{ player.height }}   


{% endfor %}




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



I'm having problem showing from the value a sub-sub model.

2011-02-21 Thread Chris
Greetings,

I'm having problem showing from the value a sub model.
I have a main model (team) I'm displaying the information, a team
contain a list players and these are listed in the page too.
So far so good, but here where its doesn't work, players have skill
and vital and I can't get to show them in the team page.

The relation between player and PlayerVital is one to one while the
relation with PlayerSkills a foreing key in the playerSkill model
mainly because skill evolve in time and we need to keep track of
that.
I tried many systax in the view but  nothing seem to work.
It seem something obvious but I can't manage to find it in the doc.

Any pointers would be helpfull.
thanks,
Chris



Here my model
class Team(models.Model):
team_name = models.CharField(max_length=200)
city = models.CharField(max_length=200) #propably FK later
def __unicode__(self):
return self.team_name


class Player(models.Model):
teamKey = models.ForeignKey(Team, blank=True, null=True)
first_name = models.CharField(max_length=200)
last_name = models.CharField(max_length=200)
def fullname(self):
return u'%s %s' % (self.first_name, self.last_name)
def __unicode__(self):
return self.fullname()

class PlayerVital(models.Model):
playerKey = models.OneToOneField(Player, primary_key=True)
POSITION = (
('G', 'Goaler'),
('D', 'Defense'),
('C', 'Center'),
('LW', 'Left Wing'),
('RW', 'Right Wing'),
)
position=models.CharField(max_length=2, choices=POSITION) #C/RW/LW/
D/G
height= models.IntegerField()
weight= models.IntegerField()
nationality = models.CharField(max_length=200)#propably FK later

class PlayerSkills(models.Model):
skill_at_date = models.DateField('skill_date')
playerKey = models.ForeignKey(Player)
SKILL_RANGE = zip( range(0,100), range(0,100))
speed=models.IntegerField(default=50, choices=SKILL_RANGE,
blank=True)
strength=models.IntegerField(default=50, choices=SKILL_RANGE,
blank=True)
endurance=models.IntegerField(default=50, choices=SKILL_RANGE,
blank=True)

Here the template
{{ object.team_name }}

{% if error_message %}{{ error_message }}{%
endif %}

{% csrf_token %}



Player Name


Position


speed


height


{% for player in object.player_set.all %}


{{ player.fullname }}  


{{ player.playerVitals_set.position }}


 
{{ player.player_set.speed }} a  


{{ playerVitals.height }}



{% endfor %}



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



Re: How to display value from a sub model in the template

2011-02-21 Thread Chris
The default (from the doc F00_set so: )
playerVital_set
and playerSkills_set

So I want the first set for each of them ...

(sorry for the double post by the way)

On Feb 20, 9:10 pm, Shawn Milochik  wrote:
> What are the related_name values you gave to the foreign key fields of
> your related models?

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



Re: I'm having problem showing from the value a sub-sub model.

2011-02-22 Thread Chris
sorry your right, I didn't receive any notification so I thought it
wasn't posted.
I've answered in the original thread

On Feb 21, 2:00 pm, Shawn Milochik  wrote:
> Why are you re-posting this? You posted it over the weekend. I
> replied. If my reply didn't help, tell us the new problem you're
> having.

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



Inline Form Error After Upgrade to Django 1.3

2011-04-18 Thread Chris
I have an inline form used in my admin that looks up the value for the
associated model, and dynamically selects the form field widget that's
appropriate for the data. The class looks like:

class MyModelInlineForm(ModelForm):
attribute_model = ModelChoiceField(queryset=None)
def __init__(self,*args,**kwargs):
...do stuff...

if not self.instance._adding:
attribute = self.instance.attribute_model
self.fields['value'] =
get_form_field_for_attribute(attribute, self.instance)

However, after upgrading to Django 1.3 from 1.2.3, viewing any admin
pages using this form throws the exception:

AttributeError: 'MyModel' object has no attribute '_adding'

I can't find any documentation on the instance._adding attribute, or
how it would have changed since 1.2.3. I've been digging through the
code, but I'm quite stuck. How do I resolve this?

Regards,
Chris

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



Re: Newbie django/python with C++ background wants enums

2012-02-01 Thread Chris
A different way would be to define constants:

YES = 'Y'
NO = 'N'

TO_USE= (
(YES, 'Yes'),
(NO, 'No'),
)

---

from myapp.models import YES

class XForm(forms.ModelForm):
def clean(self):
cleaned_data=super(XForm, self).clean()
txt= cleaned_data['txt'].strip()
use_txt=cleaned_data['use_txt'].strip()

if txt.__len__()==0 and use_txt == YES:
raise forms.ValidationError('This is needed!')

return cleaned_data

On Feb 1, 4:45 pm, NENAD CIKIC  wrote:
> Hello, the subject expresses my discomfort with certain python
> characteristics, given my background, and my lack of python knowledge.
> Specifically lets say that I have a model with a Text field and char field.
> The char field is length 1 and says "use or do not use the text field". The
> char field can have Y or N values.
> So using the admin interface I wanted to override the clean method but I
> did not want to write
> if text.__len__==0 and char=='Y':
>   raise exception
>
> In C/C++ you would use enum for these sort of things. So I ended with
> defining in models.py something as:
> TO_USE= (
>     ('Y', 'Yes'),
>     ('N', 'No'),
>     )
>
> class X(models.Model):
>     txt= models.CharField(db_index=True,null=True, blank=True,max_length=30)
>     use_txt=
> models.CharField(blank=False,max_length=1,default='D',choices=TO_USE)
>
> and in admin.py something as
> class XForm(forms.ModelForm):
>     def clean(self):
>         cleaned_data=super(XForm, self).clean()
>         txt= cleaned_data['txt'].strip()
>         use_txt=cleaned_data['use_txt'].strip()
>
>         if txt.__len__()==0 and use_txt==TO_USE.__getitem__(0)[0]:
>             raise forms.ValidationError('This is needed!')
>
>         return cleaned_data
>
> The part .__getitem__(0)[0] is not very readable. I have looked for enums
> in python, and if I have understood well, it seems they are not implemented.
> What is the best way to do it in python for my problem, given that I do not
> want to write =='Y'.
> Thanks
> Nenad

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



Re: Error

2012-02-06 Thread Chris
It's unable to find the python module openid, I would assume, that you
just don't have the openid python module installed. Since you appear
to be using linux, you should just be able to, on the command line,
do:

pip install python-openid

And it should download and install the module.

On Feb 6, 7:59 am, xina towner  wrote:
> Hi, I get this errormessage and I don't understand why:
>
> File
> "/home/xino/.virtualenvs/xinovirtualenv/local/lib/python2.7/site-packages/d 
> jango/utils/importlib.py",
> line 35, in import_module
>     __import__(name)
>   File "/home/xino/workspace/unnamedapp/unnamedapp/social_auth/urls.py",
> line 4, in 
>     from views import auth, complete, associate, associate_complete, \
>   File "/home/xino/workspace/unnamedapp/unnamedapp/social_auth/views.py",
> line 22, in 
>     from social_auth.backends import get_backend
>   File
> "/home/xino/workspace/unnamedapp/unnamedapp/social_auth/backends/__init__.p 
> y",
> line 22, in 
>     from openid.consumer.consumer import Consumer, SUCCESS, CANCEL, FAILURE
> TemplateSyntaxError: Caught ImportError while rendering: No module named
> openid.consumer.consumer
>
> Does anybody know why?
>
> --
> Gràcies,
>
> Rubén

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



Auth app in separate database

2012-03-28 Thread Chris
Has anyone been successful in putting the auth application in a
separate database so that users can be shared with different django
projects?

When I try to put the auth application in a different database I get
an error with syncdb:

django.db.utils.DatabaseError: relation "auth_permission" does not
exist
LINE 1: ...ntent_type_id", "auth_permission"."codename" FROM
"auth_perm...

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



Re: Auth app in separate database

2012-03-29 Thread Chris
I setup my router following the docs.

Here's what my router.py looks like:

AUTH_APPS = ('auth',)

class MyRouter(object):
def db_for_read(self, model, **hints):
if model._meta.app_label in AUTH_APPS:
return 'auth'
return None

def db_for_read(self, model, **hints):
if model._meta.app_label in AUTH_APPS:
return 'auth'
return None

def allow_syncdb(self, db, model):
"Make sure the Auth apps only appears on the 'auth' db"
if db == 'auth':
return model._meta.app_label in AUTH_APPS
elif model._meta.app_label in AUTH_APPS:
return False
return None

Removing auth from the default database seems to cause issues with 
contenttypes and create errors on syncdb. auth and contenttypes seem to be 
dependent on each other.

On Thursday, 29 March 2012 12:15:49 UTC-4, Josh Cartmell wrote:
>
> Couldn't he also just add the router before syncdb and then they would 
> be created in the correct database? 
>
> Chris take a look at this documentation if you haven't already, it 
> explains routers which tell Django which database to use for a 
> particular query: 
> https://docs.djangoproject.com/en/dev/topics/db/multi-db/#using-routers 
>
> On Mar 28, 9:00 pm, Amit  wrote: 
> > While running syncdb command django uses default database to create 
> > tables. 
> > You can do one thing, first create default database using syncdb then 
> > copy auth related tables to another database. 
> > Then define router for auth. You can get more ref form django 
> > documentatiion. 
> > 
> > Regards, 
> > Amit 
> > 
> > On Mar 29, 4:08 am, Chris  wrote: 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > > Has anyone been successful in putting the auth application in a 
> > > separate database so that users can be shared with different django 
> > > projects? 
> > 
> > > When I try to put the auth application in a different database I get 
> > > an error with syncdb: 
> > 
> > > django.db.utils.DatabaseError: relation "auth_permission" does not 
> > > exist 
> > > LINE 1: ...ntent_type_id", "auth_permission"."codename" FROM 
> > > "auth_perm...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/ZaoLWNLzD3sJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Appropriate way to override Model __getattr__ in 1.4

2012-06-04 Thread Chris
What's the appropriate way of overriding the a Model class's
__getattr__ in Django 1.4?

I have a model structure like:

class Main(models.Model):
[blah]

class Detail(models.Model):
   main = models.ForeignKey(Main)
   name = models.CharField(max_length=255)
   value= models.CharField(max_length=255)

I had overridden my Main._getattr__ so I could reference Detail
records as though they were normal Main attributes. e.g. a simple meta-
model pattern like

>>> m = Main.objects.create()
>>> Detail.objects.create(main=m, name='name', value='value')
>>> print m.name
'value'

To do this, my pre-1.4 __getattr__ looked like:

def __getattr__(self, attrname):
qs = self.details.filter(name=attrname)
c = len(qs)
if c == 0:
raise AttributeError
elif c == 1:
return qs[0].value
else:
return [d.value for d in qs]

This worked perfectly until I upgraded to 1.4. Now I get all types
"attribute X does not exist" errors. I tried something like the
following, but had no luck. It seems to especially conflict with the
"_*_cache" attributes Django generates for ForeignKey references.

def __getattr__(self, attrname):
try:
return super(Main, self).__getattr__(attrname)
except AttributeError:
pass
qs = self.details.filter(name=attrname)
c = len(qs)
if c == 0:
raise AttributeError
elif c == 1:
return qs[0].value
else:
return [d.value for d in qs]

How do I resolve this?

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



Custom 403.html

2012-07-10 Thread chris
I have a view that returns HttpResponseForbidden('No permission') if a user 
shouldn't be on that page. It shows the message 'No permission' and the 
correct 403 response, but nothing else. I would like it to use my 403.html 
template I have in my root template directory no match the rest of the 
site. I thought this would work in django 1.4. Is there something else I 
need to do to get it to use my custom 403.html template or am I using this 
incorrectly?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/eeakGzVTLsgJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Interesting error with django.simple.test.DjangoTestSuiteRunner

2013-02-06 Thread chris
Hi everyone,

We've been having this miscellaneous error with the default test runner in 
Django. We had a forms.py that was something like this:

class SomeForm(forms.ModelForm):
some_field = 
some_custom_fields.SomeCustomField(choices=get_some_queryset_and_evaluate_it())
# Actually, we're using django-chosen's ChosenGroupChoiceField, so 
choices is a specially-constructed 4-D list of objects

And our tests.py had:

from forms import SomeForm

Per the Django documentation, the tests are all imported before the test 
database and tables are created. This means our tests.py imports SomeForm, 
which in turn calls get_some_queryset_and_evaluate_it(), which in turn 
causes a DatabaseError: no such table: some_app_some_table, since the 
database hasn't been created yet.

So, a few questions.


   1. Should the test runner's behavior be changed?
   2. Even if it should be, what's the best way to avoid this right now? We 
   were thinking of either 
   subclassing django.simple.test.DjangoTestSuiteRunner and altering it to 
   create the database before importing tests (seems fragile), or simply 
   modifying the choices in SomeForm's __init__ method (seems hacky).

Thanks,
Chris

-- 
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: delete obsolete content type entries...

2013-03-25 Thread chris
It seems that stale content types return `None` for 
`ContentTpye.model_class()` , so the following deletes all stale content 
types. I would back up and test this extensively first though because 
deleting content type you don't want to is dangerous.

for c in ContentType.objects.all():
   if not c.model_class():
 print "deleting %s"%c
 c.delete()

On Monday, February 11, 2013 1:13:42 AM UTC-6, vijay shanker wrote:
>
> we can delete all obsolete ContentType entries manually.
> >>>for each in ContentType.objects.filter(app_label=appname): each.delete()
>  thanks
>
> On Friday, May 4, 2007 8:42:51 PM UTC+5:30, Jens Diemer wrote:
>>
>>
>> I have delete some app models. So, in the internal django tables 
>> "django_content_type" and "auth_permission" are some old content types 
>> entries.
>>
>> So i received errors like: "ContentType matching query does not exist." 
>> (When i create a new user group).
>>
>> Is there a way to update the django tables automatically?
>>
>> -- 
>> Mfg.
>>
>> Jens Diemer
>>
>>
>> 
>> A django powered CMS: http://www.pylucid.org
>>
>>

-- 
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 South - SyntaxError: invalid syntax (, line 1)

2013-10-01 Thread Chris
Ivan,

Did this code paste correctly? There is a syntax error in the save method:

 def save (self, force_insert = False, force_update = False):
 self.nome self.nome.upper = () <--- SYNTAX ERROR
 super (Carrier, self). save (force_insert, force_update)

Is that supposed to be:
self.name = self.name.upper()

?

On Monday, September 30, 2013 9:52:09 AM UTC-5, Ivan Goncalves wrote:
>
> Hi 
>
> I'm having trouble with the South.
>
> In the model below:
>
> class Carrier (models.Model):
>  name = models.CharField (max_length = 40, blank = False, null = 
> False, verbose_name = 'Name')
>  user = models.ForeignKey (User, blank = True, null = True)
> 
>  def save (self, force_insert = False, force_update = False):
>  self.nome self.nome.upper = ()
>  super (Carrier, self). save (force_insert, force_update)
> 
>  def __ unicode__ (self):
>  return u '% s'% (self.nome)
>
> the error occurs when i run the migrate after South on the app.
> SyntaxError: invalid syntax (, line 1)
>
> But if my model does not have the user field, then the error message does 
> not occur, as shown below:
>
> class Carrier (models.Model):
>  name = models.CharField (max_length = 40, blank = False, null = 
> False, verbose_name = 'Name')
> 
>  def save (self, force_insert = False, force_update = False):
>  self.nome self.nome.upper = ()
>  super (Carrier, self). save (force_insert, force_update)
> 
>  def __ unicode__ (self):
>  return u '% s'% (self.nome)
>
>
> I need the field User. What I have to do ?
>
> Thanks a lot.
>
> Ivan 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/251f724e-55fe-47b6-8436-8ab6aa966b0e%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


URL Method

2008-01-12 Thread Chris

HI I was tinkering around with this django app called basic blog
(http://code.google.com/p/django-basic-blog/) and I noticed that the
author uses a method called URL() to define his URL patterns, views,
and template objects. Should I start writing my url expressions like
this? Is it a new standard?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



generic views

2008-01-14 Thread Chris

Hello I am working with a generic view and I am trying to grab the url
expression variable and pass it to a dictionary for the generic view
to use but I keep getting an error that the variable is not defined.
Its obvious that the variable is not defined yet but is there a way
that I can make this work? Here is an example that I have. Worst case
scenario is that I create my own view which I already have but I like
to use what is already provided. Anyone have a work around to my
generic views problem?

Here is the code:
http://dpaste.com/31029/

Thanks ahead of time.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: generic views

2008-01-14 Thread Chris

I still get that error. Just forgot to add in the details variable
when I dpasted. http://dpaste.com/31049/ but I still get the same
error that I was talking about.  Should I put the details dictionary
definition below the urlpattern so that maybe the variable is defined
before I get to that point in my code?  I don't have 'request' to work
with as I do when defining my own view so for some reason I can't seem
to call directly and can't seem to find the proper accessor to grab
the tag_catagory value from the expression.

Any other suggestions as to why it is not working?




On Jan 14, 12:30 pm, Alex Koshelev <[EMAIL PROTECTED]> wrote:
> You must specify details in pattern 
> definitianhttp://www.djangoproject.com/documentation/generic_views/
>
> On 14 янв, 20:08, Chris <[EMAIL PROTECTED]> wrote:
>
> > Hello I am working with a generic view and I am trying to grab the url
> > expression variable and pass it to a dictionary for the generic view
> > to use but I keep getting an error that the variable is not defined.
> > Its obvious that the variable is not defined yet but is there a way
> > that I can make this work? Here is an example that I have. Worst case
> > scenario is that I create my own view which I already have but I like
> > to use what is already provided. Anyone have a work around to my
> > generic views problem?
>
> > Here is the code:http://dpaste.com/31029/
>
> > Thanks ahead of time.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: generic views

2008-01-14 Thread Chris

Thanks so much for your help.  Can I pass in the whole dictionary as
you do in your example?  When I attempt to do that I get this error.
dict' object has no attribute '_clone'. Alternatively I can simpley
pass in the individual variables suchas queryset and it works. I would
like to pass it in as a dictionary if at all possible.

Thanks again.

On Jan 14, 5:13 pm, Alex Koshelev <[EMAIL PROTECTED]> wrote:
> If you want to apply additional filtering for query set with parameter
> that has catched from url so you have to "inherit" generic view with
> your own. Example for your case:
>
> #views.py
> from django.views.generic.list_detail import object_list
>
> def my_view( request, tag_category ):
> CATEGORY_DETAIL = {
>  'queryset':
> Article.objects.filter(tag__tag_name__iexact=tag_category),
>  'paginate_by':15,
> }
> return object_list( request, CATEGORY_DETAIL )
>
> #urls.py
> urlpatterns = patterns('',
>     (r'^category/(?P[-\w]+)/$',
> 'my_app.views.my_view' ), )
>
> With proper names of course
>
> On 14 янв, 22:44, Chris <[EMAIL PROTECTED]> wrote:
>
> > I still get that error. Just forgot to add in the details variable
> > when I dpasted.http://dpaste.com/31049/butI still get the same
> > error that I was talking about.  Should I put the details dictionary
> > definition below the urlpattern so that maybe the variable is defined
> > before I get to that point in my code?  I don't have 'request' to work
> > with as I do when defining my own view so for some reason I can't seem
> > to call directly and can't seem to find the proper accessor to grab
> > the tag_catagory value from the expression.
>
> > Any other suggestions as to why it is not working?
>
> > On Jan 14, 12:30 pm, Alex Koshelev <[EMAIL PROTECTED]> wrote:
>
> > > You must specify details in pattern 
> > > definitianhttp://www.djangoproject.com/documentation/generic_views/
>
> > > On 14 янв, 20:08, Chris <[EMAIL PROTECTED]> wrote:
>
> > > > Hello I am working with a generic view and I am trying to grab the url
> >  > > expression variable and pass it to a dictionary for the generic view
> > > > to use but I keep getting an error that the variable is not defined.
> > > > Its obvious that the variable is not defined yet but is there a way
> >  > > that I can make this work? Here is an example that I have. Worst case
> > > > scenario is that I create my own view which I already have but I like
> > > > to use what is already provided. Anyone have a work around to my
> > > > generic views problem?
>
> > > > Here is the code:http://dpaste.com/31029/
>
> > > > Thanks ahead of time.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



tagging

2008-01-19 Thread Chris

Hello I wrote a tagging app and it is not validating when I attempt to
install it into my database. The error is related to the TAG_FILTER
tuple located in my models file. Its not validating b/c the table does
not exist. Does anyone know of a better way of doing what I am trying
to accomplish.

Code:

from django.db import models
from django.contrib.contenttypes.models import ContentType

try:
TAG_FILTER = (
(content.id,'%s | %s' % (content.app_label,content.name)) for
content in ContentType.objects.all()
)
except:
TAG_FILTER = ()

class Tag(models.Model):
"""Tagging model"""
name = models.CharField(max_length=25,)
slug = models.SlugField(choices=TAG_FILTER)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: tagging

2008-01-19 Thread Chris

Never mind had a brain fart. I should use
models.ForeignKey(ContentType,).

On Jan 19, 4:36 pm, Chris <[EMAIL PROTECTED]> wrote:
> Hello I wrote a tagging app and it is not validating when I attempt to
> install it into my database. The error is related to the TAG_FILTER
> tuple located in my models file. Its not validating b/c the table does
> not exist. Does anyone know of a better way of doing what I am trying
> to accomplish.
>
> Code:
>
> from django.db import models
> from django.contrib.contenttypes.models import ContentType
>
> try:
> TAG_FILTER = (
> (content.id,'%s | %s' % (content.app_label,content.name)) for
> content in ContentType.objects.all()
> )
> except:
> TAG_FILTER = ()
>
> class Tag(models.Model):
> """Tagging model"""
> name = models.CharField(max_length=25,)
> slug = models.SlugField(choices=TAG_FILTER)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Post Save

2008-01-21 Thread Chris

I have a weblog that I am creating and it has a table with fields
called title and url_name.  I would like to make it possible for the
user to simply enter the title of the blog and then django would auto
format the url_name for me based off of the title. ex. - title = My
First Blog -->gets translated to --> url_name = my_first_blog.  I
recall something called _post_save(self): which is defined in your
models class but I am not sure how that would work for what I am
doing.  Anyone have any suggestions? or better way of doing this?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django media project

2008-01-21 Thread Chris

Hello I just opened a new project on google code and I was wondering
if there was anyone that would be willing to help me work on this
project in their free time. Check it out. http://code.google.com/p/megal/
Please give me feed back too. Hope I am not violating any rules by
posting this here. It is a django based project. Thanks.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



category counter

2008-01-24 Thread Chris

hello again. thanks for all the help that everyone has offered me
here.

I have a generic django application called categories and it serves to
provide categories for various apps suchas a weblog or an articles
application. So a weblog and article app both have a M2M relation to
the catergories app. what I am wanting to do is count how many
occurrences of a category are found for a particular application. So
if my weblog had a category called politics, it would count how many
weblogs have a relation with that. Is this possible with out putting a
category_counter field in? I notice that there is a .count() method
but not really sure how to apply it to what I am attempting to do.

-model looks like:
name
slug
content_type

-my call:
test =
Category.objects.filter(content_type__app_label__exact='weblog')
how would I count the number of occurrences of a category called
politics?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: category counter

2008-01-25 Thread Chris

Cool here is my models and I posted an sql query to:

Models
http://dpaste.com/32548/

SQL Queries (posted a question in this one)
http://dpaste.com/32552/

Hope this helps. maybe there is a better way of doing what I am trying
to do.

Thanks for helping.


On Jan 25, 12:59 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
> On Jan 25, 12:42 pm, Chris <[EMAIL PROTECTED]> wrote:
>
> > Thanks for reply but that is not what I am looking to do. my [EMAIL 
> > PROTECTED] table
> > is NOT the categories table.
>
> Well, as I said in my earlier post, you still haven't posted your
> model code. It would help people understand better what you are trying
> to do.
>
> > In django, when it generates your models,
> > it automatically generates your M2M table reference. so I have a table
> > called blog that has a m2m relation with categories. 
> > (blog-->M2M-->categories) Right! Ok so using distinct on the category table 
> > would
>
> > NOT work since they would already be distinct. The table that I need
> > to grab results from is the M2M table NOT categories.  Make sense?
>
> Not really.
>
> You said previously that you needed to count the number of blogs for a
> given category ('politics'). The query I mentioned originally, does
> that. Incidentally, the distinct() in my query is on the Blog model
> and not on the Category model.
>
> You don't need to grab results directly from the automatically
> generated M2M table to get the count you are interested in. You could,
> of course, fetch results directly from the M2M table using custom sql
> but it's not necessary unless you want to do something other than what
> you say you want to do :) In that case, please consider posting your
> model.
>
> Cheers,
> -Rajesh
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



dynamic model calls

2008-01-25 Thread Chris

Hello,

I am seeking to do something like this:

def dynamic_model_call(model_name):
test = model_name.objects.all()
return test

I saw where I could do something like this:
def dynamic_model_call(model_name):
exec("test = %s.objects.all()" % model_name)
return test

But this doesn't look like an appropriate solution.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: category counter

2008-01-25 Thread Chris

Cool. I tried that early and it didn't work. I just tried it again and
it seems to work. must of keyed something in wrong.

>>> Weblog.objects.filter(category__id='1').count()
3L

Thanks for your help.


On Jan 25, 2:08 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
> On Jan 25, 2:01 pm, Chris <[EMAIL PROTECTED]> wrote:
>
> > Cool here is my models and I posted an sql query to:
>
> > Modelshttp://dpaste.com/32548/
>
> > SQL Queries (posted a question in this one)http://dpaste.com/32552/
>
> > Hope this helps. maybe there is a better way of doing what I am trying
> > to do.
>
> Is this a fair characterisation of what you are trying to do? Given a
> category title or id, you want to get the total number of Weblog
> objects which have that category.
>
> If yes,  what do you get if you drop into the shell and run any of
> these queries?
>
> Weblog.objects.filter(category__title='programming').count()
>
> or
>
> Weblog.objects.filter(category__id=1).count()
>
> or
>
> c = Category.objects.get(id=1)
> c.weblog.count()
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: category counter

2008-01-25 Thread Chris

Thanks for reply but that is not what I am looking to do. my [EMAIL PROTECTED] 
table
is NOT the categories table. In django, when it generates your models,
it automatically generates your M2M table reference. so I have a table
called blog that has a m2m relation with categories. (blog-->M2M--
>categories) Right! Ok so using distinct on the category table would
NOT work since they would already be distinct. The table that I need
to grab results from is the M2M table NOT categories.  Make sense?

On Jan 25, 12:03 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
> >  so if category_id 2 name is 'politics' it would know that it occurs 3
> > times. make sense?  The easy way would be to create a counter field in
> > the categories table and count each time that the category is being
> > used but that is redundant and require extra work to save the category
> > count each time I add a new entry.  The answer is already there I just
> > need to figure out how to retrieve that answer. :)
>
> You didn't include your full model, but have you tried something like
> this?
>
> Blog.objects.filter(categories__name='politics').distinct().count()
>
> This assumes that Blog.categories is your M2M field.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: category counter

2008-01-25 Thread Chris

Thanks for the response. If only it were that easy :). In my
categories table, each category should be unique. What I am trying to
count is the m2m ref table.

Example.
category_id | name
1 | programming
2 | politics
3 | games

blog_id | category_id

1 | 2  <-- I am trying to reference this table and count how many
times each unique tag name is used.
1 | 3
2 | 1
2 | 2
3 | 3
3 | 2

 so if category_id 2 name is 'politics' it would know that it occurs 3
times. make sense?  The easy way would be to create a counter field in
the categories table and count each time that the category is being
used but that is redundant and require extra work to save the category
count each time I add a new entry.  The answer is already there I just
need to figure out how to retrieve that answer. :)


On Jan 25, 9:00 am, Thomas Guettler <[EMAIL PROTECTED]> wrote:
> Hi,
>
> There are two ways of counting:
>
> # Bad way:
> len(MyModel.objects.filter(...))
>
> This will fetch all rows  (SELECT * FROM ... WHERE ...;)
>
> # Good way:
> MyModel.objects.filter(...).count()
>
> This will do the couting at the database
> SELECT COUNT(*) FROM ... WHERE ...;
>
> If you know how to get all categories by using filter(), just
> put .count() at the end and you get the result.
>
> HTH,
>  Thomas Güttler
>
> Am Freitag, 25. Januar 2008 08:47 schrieb Chris:
>
> > hello again. thanks for all the help that everyone has offered me
> > here.
>
> > I have a generic django application called categories and it serves to
> > provide categories for various apps suchas a weblog or an articles
> > application. So a weblog and article app both have a M2M relation to
> > the catergories app. what I am wanting to do is count how many
> > occurrences of a category are found for a particular application. So
> > if my weblog had a category called politics, it would count how many
> > weblogs have a relation with that. Is this possible with out putting a
> > category_counter field in? I notice that there is a .count() method
> > but not really sure how to apply it to what I am attempting to do.
>
> > -model looks like:
> > name
> > slug
> > content_type
>
> > -my call:
> > test =
> > Category.objects.filter(content_type__app_label__exact='weblog')
> > how would I count the number of occurrences of a category called
> > politics?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



dynamic tag count

2008-01-29 Thread Chris

Hello I have a Tagging app that I have created which could have a m2m
relation with several other applications suchas a weblog, projects,
articles,etc...

I am trying to do something like this:

tag_list = Tag.objects.all()

for tag in tag_list:
print tag.weblog.count()

Is there a way to dynamically call tag.[this_model].count(). since
this tagging app can be associated with more than one app. (replacing
this_model with the appropriate model name.)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



A slug question

2008-01-31 Thread Chris

I have a blog that has a slug field that gets pre-populated from the
title of the blog. I then use the slug name as a part of the url. eg -
www.xyz.com/weblog/weblog-title-goes-here/. My question: what if I
have a weblog title that is identical to a post that I made 3 years
ago and I didn't realize it? when saving, is the slugfield smart
enough to acknowledge that there is a duplicate entry. If so how would
it correct the problem (www.xyx.com/weblog/weblog-title-goes-
here-2/)?  If no how do I correct that problem.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: A slug question

2008-01-31 Thread Chris

Cool Thanks for the replies. I think that Luke's snippet find is going
to work. Unique is also a good way thanks.


On Jan 31, 5:15 pm, "James Punteney" <[EMAIL PROTECTED]> wrote:
> >  My question: what if I
> > have a weblog title that is identical to a post that I made 3 years
> > ago and I didn't realize it? when saving, is the slugfield smart
> > enough to acknowledge that there is a duplicate entry.
>
> The slug field itself doesn't force uniqueness, but you can use
> "unique=True" to ensure 
> this.http://www.djangoproject.com/documentation/model-api/#unique
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



User permissions

2008-01-31 Thread Chris

I've been reading up on user permissions and I have found that user
permissions are on a per-model basis. My question: If I have a photo
gallery application, and I have several uses who can post their
galleries to this application. Is there a way to create permission on
a per-user basis. Example maybe I created a gallery called 'The
Rockies' but I only want Bob, Susan, and Tim to see it, Is this
possible with the built in permissions? or would I have to create a
table column similar to is_public = models.booleanField().
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Code upgrade

2008-02-05 Thread Chris

Hello, does anyone have a script that will upgrade django code from .
91 to .96.  I know that there are upgrade scripts out there just not
sure where I can obtain them. Would very much like to upgrade code
repository to 96.

thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Code upgrade

2008-02-05 Thread Chris

so does anyone have such a script on hand.  I have partially written
one that uses regular expressions to evaluate everything but I think
that it is still quite a ways off from getting it to a working point.

On Feb 5, 1:52 pm, "James Bennett" <[EMAIL PROTECTED]> wrote:
> On Feb 5, 2008 12:33 PM, David Marquis <[EMAIL PROTECTED]> wrote:
>
> > If you didn't make any change to the Django source base, you can
> > simply download the latest release and install the new version.
> > If needed, you could also download the latest development version
> > through the Subversion repository.
>
> No, he can't. Between Django 0.91 and Django 0.95 there were huge
> numbers of massive backwards-incompatible changes; code that ran on
> 0.91 and earlier has to be fairly thoroughly rewritten in order to run
> on 0.95 or higher.
>
> The full list of necessary changes is preserved here:
>
> http://code.djangoproject.com/wiki/RemovingTheMagic
>
> --
> "Bureaucrat Conrad, you are technically correct -- the best kind of correct."
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Code upgrade

2008-02-06 Thread Chris

James,

Does magic removal help to upgrade code from 91 to present or is it a
set of code used to assist with writing a potential application that
could do this?

Thanks for all your help. You are very helpful on this forum.

Chris

On Feb 5, 3:17 pm, Chris <[EMAIL PROTECTED]> wrote:
> so does anyone have such a script on hand.  I have partially written
> one that uses regular expressions to evaluate everything but I think
> that it is still quite a ways off from getting it to a working point.
>
> On Feb 5, 1:52 pm, "James Bennett" <[EMAIL PROTECTED]> wrote:
>
> > On Feb 5, 2008 12:33 PM, David Marquis <[EMAIL PROTECTED]> wrote:
>
> > > If you didn't make any change to the Django source base, you can
> > > simply download the latest release and install the new version.
> > > If needed, you could also download the latest development version
> > > through the Subversion repository.
>
> > No, he can't. Between Django 0.91 and Django 0.95 there were huge
> > numbers of massive backwards-incompatible changes; code that ran on
> > 0.91 and earlier has to be fairly thoroughly rewritten in order to run
> > on 0.95 or higher.
>
> > The full list of necessary changes is preserved here:
>
> >http://code.djangoproject.com/wiki/RemovingTheMagic
>
> > --
> > "Bureaucrat Conrad, you are technically correct -- the best kind of 
> > correct."
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



comment system

2008-02-09 Thread Chris

hello. I have been looking at django's comment system and am going to
implement it into my weblog but was wondering how stable it is. (If
'stable' is the proper word to use). In the django book it states that
the comment system is still under heavy development and on the site
there is not much documentation on how to use the comment system to
its fullest potential.  I don't want to use something that is still
under heavy development and later have to go back and rewrite things b/
c of major changes that took place. So I was wondering if I should use
django's comment system or use my own comment system?

Thanx
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



embed to models forms in the same form

2008-02-09 Thread Chris

In the admin panel if I have a model called books and a model called
author, and books has a FK to author, is there a way to import the
form for author to show up in the books form instead of having the
dropdown menu or some kind of pop up window that takes you to the
author form. I want it embedded right into the books form.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



forms question

2008-02-14 Thread Chris

will there ever be an forms.as_div method? tables seems kinda old
school.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



ViewDoesNotExist admin error.

2008-03-04 Thread Chris

Hello,
Not sure what has happened but I keep getting this error when
attempting to login to my admin section. I key in Username and pass
and once I press submit django returns this error:

Request Method: GET
Request URL:http://django.xyz.net/admin/
Exception Type: ViewDoesNotExist
Exception Value:Tried views in module profiles. Error was: 'module'
object has no attribute 'views'
Exception Location: /srv/django-0.96/django/core/urlresolvers.py in
_get_callback, line 184
Python Executable:  /usr/bin/python


Any Ideas as to what is going on here?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django-UML Generator

2008-03-25 Thread Chris

So I had this idea and was looking for some thoughts on this:
When starting a new website, normally a client gives you a handful of
documents
on what he/she wants. Most of the time this person is technically
illiterate so
interpreting what he/she into a django model is often a challenge.
i propose this cool idea called a the django-uml generator that would
work my simply doing
this: python manage.py umlgen SOME_MODEL_NAME and magically you have
a
nice type of document or some data the could import into a document
based upon how the
model was defined. How would this be useful? In return to the non
technical documentation
that was given you would have some sort of document that you could go
over with the client
to make sure what was written in their documentation meets what you
output from the models
before you syncdb and doing further coding. It seems like you could
save a lot of headaches
at a later point with this method. Thoughts?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django-UML Generator

2008-03-25 Thread Chris

Thanks for your responses. Thanks Malcolm that helped alot.


On Mar 25, 1:43 pm, "Justin Lilly" <[EMAIL PROTECTED]> wrote:
> You expect to hand a non-technical client something that looks like:
>
> http://blog.riff.org/files/Project8.png
>
> ?? I thing that would go poorly. Besides, pencil + paper goes a long
> way in client discussions like that.
>
>  -justin
>
>
>
> On Tue, Mar 25, 2008 at 1:22 PM, Chris <[EMAIL PROTECTED]> wrote:
>
> > So I had this idea and was looking for some thoughts on this:
> > When starting a new website, normally a client gives you a handful of
> > documents
> > on what he/she wants. Most of the time this person is technically
> > illiterate so
> > interpreting what he/she into a django model is often a challenge.
> > i propose this cool idea called a the django-uml generator that would
> > work my simply doing
> > this: python manage.py umlgen SOME_MODEL_NAME and magically you have
> > a
> > nice type of document or some data the could import into a document
> > based upon how the
> > model was defined. How would this be useful? In return to the non
> > technical documentation
> > that was given you would have some sort of document that you could go
> > over with the client
> > to make sure what was written in their documentation meets what you
> > output from the models
> > before you syncdb and doing further coding. It seems like you could
> > save a lot of headaches
> > at a later point with this method. Thoughts?
>
> --
> Justin Lilly
> Web Developer/Designerhttp://justinlilly.com
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



ORM / General Database Question

2008-04-02 Thread Chris

I've done this without questioning it ever since I can remember : no
matter what, assign a primary key to everything.

Is this necessary when you have a ForeignKey relation? Can the
ForeignKey be the unique identifier in the table?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



middleware question

2008-04-02 Thread Chris

Is there a way to grab content_type and object_id in a middleware
processor? Example if I went to my articles section:
http://www.xyz.com/articles// could I some how get the
content_type and the object_id from the request context that is passed
in? I want to be able to perform a middleware task but need to know
what model and object that I am dealing with.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: middleware question

2008-04-02 Thread Chris

Can anyone help me with this? It looks like I need to pass in a
django_content_type= to the request context
before it gets passed to the middleware for further processing. Any
thoughts?

On Apr 2, 3:37 pm, Chris <[EMAIL PROTECTED]> wrote:
> Is there a way to grab content_type and object_id in a middleware
> processor? Example if I went to my articles 
> section:http://www.xyz.com/articles// could I some how get the
> content_type and the object_id from the request context that is passed
> in? I want to be able to perform a middleware task but need to know
> what model and object that I am dealing with.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Populate_xheaders

2008-04-03 Thread Chris

Hello, why does populate_xheaders only work if you are authenticated
and staff OR if the request comes from an internal IP?  It would be
nice if I could have these: response['X-Object-Type']
response['X-Object-Id']
for normal requests to work with middleware that I am writing.

Is it a security reason?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Populate_xheaders

2008-04-03 Thread Chris

Any suggestions? Hope everyone is having a fabulous day! Thanks for
all the help you all have provided here.

On Apr 3, 10:35 am, Chris <[EMAIL PROTECTED]> wrote:
> Hello, why does populate_xheaders only work if you are authenticated
> and staff OR if the request comes from an internal IP?  It would be
> nice if I could have these: response['X-Object-Type']
> response['X-Object-Id']
> for normal requests to work with middleware that I am writing.
>
> Is it a security reason?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Populate_xheaders

2008-04-04 Thread Chris

Does anyone have some input to this?


On Apr 3, 1:18 pm, Chris <[EMAIL PROTECTED]> wrote:
> Any suggestions? Hope everyone is having a fabulous day! Thanks for
> all the help you all have provided here.
>
> On Apr 3, 10:35 am, Chris <[EMAIL PROTECTED]> wrote:
>
> > Hello, why does populate_xheaders only work if you are authenticated
> > and staff OR if the request comes from an internal IP?  It would be
> > nice if I could have these: response['X-Object-Type']
> > response['X-Object-Id']
> > for normal requests to work with middleware that I am writing.
>
> > Is it a security reason?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Article Count

2008-04-04 Thread Chris

If I have an article model that has an article_count field, would it
be better to increment the article when you grab the article in the
view or increment with middleware? and how about when caching is
involved?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Article Count

2008-04-04 Thread Chris

number of views.

On Apr 4, 11:05 am, "Richard Dahl" <[EMAIL PROTECTED]> wrote:
> I think it depends on exactly what article_count is.  Is it the number of
> views of the article? The total number of articles? The number of articles
> related to this article?  I am just not sure what you are trying to
> accomplish.
> -rfd
>
> On 4/4/08, Chris <[EMAIL PROTECTED]> wrote:
>
>
>
> > If I have an article model that has an article_count field, would it
> > be better to increment the article when you grab the article in the
> > view or increment with middleware? and how about when caching is
> > involved?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



model subclassing

2008-04-08 Thread Chris

I am trying create a custom model field that will create 2 field
instances, a CharField and a booleanField. I am using this with
signals and dispatchers to insert data entered from this custom field
into another model/table that contains a boolean and char field. my
question is: how can I return 2 field objects in a single model
subclass class. Seems like it would be similar to what occurs in
datetimeField but not sure how to implement. so end result would look
something like this:

some_model(models.Model):
fields = customFields()

so that I don't have to do something like this in the model that I
will be calling this from

some_model(models.Model):
field_1 = customField1()
field_2 = customField2()

Any pointers on how to do this?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: model subclassing

2008-04-09 Thread Chris

Thanks looks very helpful. I will look over that when I get a free
moment.


On Apr 9, 10:39 am, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
> Hi,
>
> On Apr 9, 12:30 am, Chris <[EMAIL PROTECTED]> wrote:
>
> > I am trying create a custom model field that will create 2 field
> > instances, a CharField and a booleanField. I am using this with
> > signals and dispatchers to insert data entered from this custom field
> > into another model/table that contains a boolean and char field. my
> > question is: how can I return 2 field objects in a single model
> > subclass class. Seems like it would be similar to what occurs in
> > datetimeField but not sure how to implement. so end result would look
> > something like this:
>
> 
>
>
>
> > Any pointers on how to do this?
>
> Download the PDF from here and look at the Custom Model Fields 
> slides:http://toys.jacobian.org/presentations/2007/oscon/tutorial/
>
> -Rajesh D
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



django calendar for a datatime field

2008-04-15 Thread Chris

Hello friends,
Is there a simple way to add the calendar widget (as seem in admin)
into a custom form field such as if I have a form with a date of birth
field?

Thanks in advance!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



login with email

2008-04-17 Thread Chris

hello, I am working on a website where our client wants to login
through use of an email. I have the registration part figured out but
when I go to login as shown here:

http://dpaste.com/45576/

I can't get a user object to return from authenticate. any
suggestions?

thanks in advance!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: login with email

2008-04-17 Thread Chris

> Unless you imported Auth into the local namespace you need to call
> auth.authenticate().


Thanks for the humor!!  :)

>>> from django.contrib.auth import authenticate, login
>>> test = authenticate(username="testuser", password="testpass")
>>> test



If that were the case it would more than likely through an import
error which it is not. I use this same bit of code to login the use
when they complete registration. Its when the user goes to login it
does not return a user object to complete the login request.


On Apr 17, 4:51 pm, jonknee <[EMAIL PROTECTED]> wrote:
> > I can't get a user object to return from authenticate. any
> > suggestions?
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Authenticate

2008-04-21 Thread Chris

So I have created a user profile model the extends the User model. I
am having issues with trying to authenticate. So I gather some
information and and attempt to save it out but when I go to
authenticate shorty after, the auth.authenticate does not return a
user object therefore not logging the user in:

userprofile.address = request.POST['address']
userprofile.city = request.POST['city']
userprofile.state = request.POST['state']
userprofile.country = request.POST['country']
userprofile.website = request.POST['website']
userprofile.user.set_password(POST['password'])
userprofile.save()

user = auth.authenticate(username=POST['username'],
password=POST['password'])
if user is not None and user.is_active:
auth.login(request, user)
return HttpResponseRedirect(success_url)

So the problem that I have discovered is that when saving a password
to the user model is that you have to call an instance of the User
model to save a password and for authentication method to work
correctly. In the example above I try to save my password from the
userprofile instance through inheritance but it does not seem to save
the password.

So instead of this:

userprofile.user.set_password(POST['password'])
userprofile.save()

I have to call this separately:

django_user = User.objects.get(username__exact=POST['username'])
django_user.set_password(POST['password'])
django_user.save()

Authentication works perfectly on the latter method. Why would one
work but not the other?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



authenicate

2008-04-28 Thread Chris

Anyone see what I am doing wrong here?

http://dpaste.com/47296/

Thanks in advance.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: authenicate

2008-04-28 Thread Chris

Sorry I was kind of vague on that. The error that I was getting was
the raise - 'Somethng Went Wrong'. But I did figure it out. The reason
for the error was related to another issue that I resolved. Thanks for
responding and being so supportive.


On Apr 28, 4:35 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Mon, Apr 28, 2008 at 4:01 PM, Chris <[EMAIL PROTECTED]> wrote:
>
> > Anyone see what I am doing wrong here?
>
> >http://dpaste.com/47296/
>
> > Thanks in advance.
>
> You put some of your close parens in odd places.
>
> Not the kind of help you are looking for?  Perhaps include in your request
> for help a description of the error you are encountering, or how the
> behavior you are observing differs from what you expect, and the code for
> your login form and template referenced by the snippet you posted.
>
> Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



file upload question

2008-05-06 Thread Chris

Hello I have a csv importer that I have made and I want to upload the
csv file through a form field as so:

from django import newforms as forms

class ImportForm(forms.Form):
"""
Form for importing CSV files
"""
csv_file = forms.FileField()

next I do something like this:

form = ImportForm()
if request.method == 'POST':
form = ImportForm(request.POST, request.FILES)
if form.is_valid():
if ‘csv_file’ in request.FILES:
try:
csv_file = request.FILES[‘csv_file’][‘content’]
except:
request.FILES[‘csv_file’][‘error’] = True

I am not really sure what I need to do here to get the file and store
it somewhere. right now it is returning the exception. Any suggestions?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Custom Form Fields

2008-05-07 Thread Chris

Hello everyone,  I noticed that Django tagging uses a custom field
called TagField that allows you to insert tags directly relating to
your application you inserted TagField in. Is there an easier way of
accomplishing the same type of results that django tagging does with
Tagfield()? I want to be able to create a CustomField that will output
to form fields (TextField and BooleanField) from another application
and then when I save the results it will go out the that application
and save those 2 fields. Keep in mind, I do not want to use
ForeignKeys or M2M relationships. I want the fields from application2
to be embeded directly into application1.

e.g -

class SomeModel1(models.Model):
"""This model adopts the CustomField feature"""
some_field1 = models.CharField(max_length=255)
custom_field =  CustomField()


class SomeModel2(models.Model):
"""This is the model that data will be saved out through the use
of CustomField"""
object_id = models.IntegerField()
some_field2 = models.CharField(max_length=25)
some_field3 = models.BooleanField()

So when I attempt to insert into SomeModel1 through the admin
interface, I will see something like this:

some_field1   _
some_field2  __
some_field3  __

then when I go to save, CustomField will know to save the data from
field 2 and 3 to SomeModel2. Is there an easy way to do this? Is there
some intuitive documentation somewhere on how to do something similar
to what Django tagging is doing?

Thanks in advance.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Group by for querysets

2008-05-09 Thread Chris

Is there a group_by method when getting querysets?  Check out the
following example.

class SportsEvent(models.Model):
"""Sports"""
name = models.CharField(max_length=255)
sport_type = models.ForeignKey(Sport)
event_date = models.DateTimeField()

class Sport(models.Modle):
"""sports"""
sport_name = models.CharField(max_length=255)

so I would like to be able to do something like this:

events_by_group =
SportsEvent.objects.group_by("sport_type").order_by("event_date")

and hopefully get something like this:

[, , ,]

and each  would contain SportsEvents objects.
[, ,  ]

so...

Basketball
-
January 2
March 8
May 10

Football

January 10
February 16
June 21

and so on...

Does django carry something similar to what I am looking for? If not,
would a group_by feature be something worth adding to django?


Thanks in Advance.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Strange New Forms Issue

2008-05-14 Thread Chris

Hello I created a new forms form and I am having uses with this
statement:

year_of_birth = forms.ChoiceField(required=False,
choices=YEAR_OF_BIRTH)

and tuple looks like so:
year_of_birth = ((1990, '1990'), (1989, '1989'), ...)

On my local dev server, I have latest django and use sqllite, this
works fine but when I push code to our company dev server and try to
run code it, it breaks and give me the following message. On the
company dev we use mysql. This almost looks like it could be a mysql
specific bug but the error is so vague who knows. I don't understand
how I can pass a tuple through and it think that I am giving it a ''
value.

Exception Type: Warning
Exception Value:Incorrect integer value: '' for column
'year_of_birth' at row 1
Exception Location: /usr/lib/python2.5/site-packages/MySQLdb/
cursors.py in _warning_check, line 80

Could someone please help. This error is driving me crazy!

Thanks in advance.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Strange New Forms Issue

2008-05-15 Thread Chris

Could someone help me out with this error or Warning as it states in
the exception?

On May 14, 6:14 pm, Chris <[EMAIL PROTECTED]> wrote:
> Hello I created a new forms form and I am having uses with this
> statement:
>
> year_of_birth = forms.ChoiceField(required=False,
> choices=YEAR_OF_BIRTH)
>
> and tuple looks like so:
> year_of_birth = ((1990, '1990'), (1989, '1989'), ...)
>
> On my local dev server, I have latest django and use sqllite, this
> works fine but when I push code to our company dev server and try to
> run code it, it breaks and give me the following message. On the
> company dev we use mysql. This almost looks like it could be a mysql
> specific bug but the error is so vague who knows. I don't understand
> how I can pass a tuple through and it think that I am giving it a ''
> value.
>
> Exception Type: Warning
> Exception Value:Incorrect integer value: '' for column
> 'year_of_birth' at row 1
> Exception Location: /usr/lib/python2.5/site-packages/MySQLdb/
> cursors.py in _warning_check, line 80
>
> Could someone please help. This error is driving me crazy!
>
> Thanks in advance.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Strange New Forms Issue

2008-05-15 Thread Chris

Hi Karen,

I have a form with first_name, last_name and email and once the user
presses submit, it will then save the 3 required fields to the
database and send the data to another form containing additional
fields suchas year_of_birth, phone_number, address,city, state, etc...
The 3 required fields have already been filled out by a user in the
first form, the next form it sends data to contains optional fields. I
am not using form wizard either, just a render_to_response that passes
data to the next form. Why it works on my local dev and not on the
company dev makes no sense.

model field declaration looks like this:

year_of_birth = models.IntegerField(blank=True, null=True,
choices=YEAR_OF_BIRTH)

also I I noticed when I take out the ChoicesField altogether it seems
to process fine or if I change field to a textfield it works too.

Thanks for helping me with this strange issue.

Chris



On May 15, 9:38 am, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Wed, May 14, 2008 at 6:14 PM, Chris <[EMAIL PROTECTED]> wrote:
>
> > Hello I created a new forms form and I am having uses with this
> > statement:
>
> >year_of_birth = forms.ChoiceField(required=False,
> > choices=YEAR_OF_BIRTH)
>
> > and tuple looks like so:
> >year_of_birth = ((1990, '1990'), (1989, '1989'), ...)
>
> > On my local dev server, I have latest django and use sqllite, this
> > works fine but when I push code to our company dev server and try to
> > run code it, it breaks and give me the following message. On the
> > company dev we use mysql. This almost looks like it could be a mysql
> > specific bug but the error is so vague who knows. I don't understand
> > how I can pass a tuple through and it think that I am giving it a ''
> > value.
>
> > Exception Type: Warning
> > Exception Value:Incorrect integer value: '' for column
> > 'year_of_birth' at row 1
> > Exception Location: /usr/lib/python2.5/site-packages/MySQLdb/
> > cursors.py in _warning_check, line 80
>
> > Could someone please help. This error is driving me crazy!
>
> > Thanks in advance.
>
> You don't mention when you get this error: all of the time, regardless of
> the choice, only when the 'blank' choice is chosen, etc?  MySQL is
> complaining that it is being handed and empty string to put in an integer
> field.  I notice you have required=False on the form field, so I'd guess you
> are seeing this only when the 'blank' choice is chosen, in which case I
> suspect the fix would be to specify null=True in the model field, so that
> blank will be stored as null in the database.
>
> Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Strange New Forms Issue

2008-05-15 Thread Chris

Cool I resolved the error. So when you have a drop down list for an
IntegerField that is an optional IntegerField in the database, you
must set some sort of validation to tell this optional field to be
None (for the obvious reasons). What I didn't realize is when I had a
choices list set in the Choicefield which was optional, django puts in
a (("","--"),) at the top of the list. So for others who might
have this problem make sure to set None to an optional IntegerField in
your model when validating or right before saving.

This is a general question to the Django Community? Should there be
some automation that realizes that it is a choices list for an
IntegerField and should not include this " " but should include this
None as the default blank field?




On May 15, 12:21 pm, Chris <[EMAIL PROTECTED]> wrote:
> Hi Karen,
>
> I have a form with first_name, last_name and email and once the user
> presses submit, it will then save the 3 required fields to the
> database and send the data to another form containing additional
> fields suchas year_of_birth, phone_number, address,city, state, etc...
> The 3 required fields have already been filled out by a user in the
> first form, the next form it sends data to contains optional fields. I
> am not using form wizard either, just a render_to_response that passes
> data to the next form. Why it works on my local dev and not on the
> company dev makes no sense.
>
> model field declaration looks like this:
>
> year_of_birth = models.IntegerField(blank=True, null=True,
> choices=YEAR_OF_BIRTH)
>
> also I I noticed when I take out the ChoicesField altogether it seems
> to process fine or if I change field to a textfield it works too.
>
> Thanks for helping me with this strange issue.
>
> Chris
>
> On May 15, 9:38 am, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
>
> > On Wed, May 14, 2008 at 6:14 PM, Chris <[EMAIL PROTECTED]> wrote:
>
> > > Hello I created a new forms form and I am having uses with this
> > > statement:
>
> > >year_of_birth = forms.ChoiceField(required=False,
> > > choices=YEAR_OF_BIRTH)
>
> > > and tuple looks like so:
> > >year_of_birth = ((1990, '1990'), (1989, '1989'), ...)
>
> > > On my local dev server, I have latest django and use sqllite, this
> > > works fine but when I push code to our company dev server and try to
> > > run code it, it breaks and give me the following message. On the
> > > company dev we use mysql. This almost looks like it could be a mysql
> > > specific bug but the error is so vague who knows. I don't understand
> > > how I can pass a tuple through and it think that I am giving it a ''
> > > value.
>
> > > Exception Type: Warning
> > > Exception Value:Incorrect integer value: '' for column
> > > 'year_of_birth' at row 1
> > > Exception Location: /usr/lib/python2.5/site-packages/MySQLdb/
> > > cursors.py in _warning_check, line 80
>
> > > Could someone please help. This error is driving me crazy!
>
> > > Thanks in advance.
>
> > You don't mention when you get this error: all of the time, regardless of
> > the choice, only when the 'blank' choice is chosen, etc?  MySQL is
> > complaining that it is being handed and empty string to put in an integer
> > field.  I notice you have required=False on the form field, so I'd guess you
> > are seeing this only when the 'blank' choice is chosen, in which case I
> > suspect the fix would be to specify null=True in the model field, so that
> > blank will be stored as null in the database.
>
> > Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Form Fields Question

2008-05-21 Thread Chris

Why does django by default output html id's in form fields? I thought
that it was good practice to use the class attribute in child elements
of an html form and to only use id on your container (parent) element
such as the form element. I think I read somewhere that classes are
faster to create and that id's are much slower to create.

Thanks in advance.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form Fields Question

2008-05-21 Thread Chris

>>and in 2008, does it really matter?

If you are managing a major media related site every inch counts in
order to have a fast and deliverable page!

I wasn't saying that django was performing bad practice, I was just
curious as to why id over classes.

Thanks for the input.




On May 21, 3:32 pm, "Marty Alchin" <[EMAIL PROTECTED]> wrote:
> On Wed, May 21, 2008 at 3:16 PM, Chris <[EMAIL PROTECTED]> wrote:
> > Why does django by default output html id's in form fields? I thought
> > that it was good practice to use the class attribute in child elements
> > of an html form and to only use id on your container (parent) element
> > such as the form element. I think I read somewhere that classes are
> > faster to create and that id's are much slower to create.
>
> I don't know about the speed of id versus class (and in 2008, does it
> really matter?), but keep in mind that, by default, Django's forms
> also use the label element, with its "for" attribute.[1] By
> definition, that attribute must match to an *id* of a form field in
> order to work properly. With that in mind, I certainly can't imagine
> any reason by assigning an id to a form field would be bad practice.
>
> -Gul
>
> [1]http://www.w3.org/TR/html401/interact/forms.html#adef-for


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Form Fields Question

2008-05-21 Thread Chris

> Well if you are using AJAX it's necessary to have the id of an html

That is not necessarily true! There are lots of ways for a programmer
to access their elements and update them through ajax. You should
checkout mootools.net.





On May 21, 7:40 pm, Jashugan <[EMAIL PROTECTED]> wrote:
> On May 21, 2:05 pm, Chris <[EMAIL PROTECTED]> wrote:
>
> > I wasn't saying that django was performing bad practice, I was just
> > curious as to why id over classes.
>
> > Thanks for the input.
>
> Well if you are using AJAX it's necessary to have the id of an html
> element set, so that the javascript function would know which element
> to update. I find them pretty useful
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: package directory \django does not exist

2008-06-01 Thread Chris

Python isn't checking your Desktop for modules.  Untar it under your 
python directory.  Preferably, "site packages"

slix wrote:
> i untared the official download and ran setup.py install from the
> desktop where it is placed.
> 
> should i first place the django, docs and scripts folders in site-
> packages? i thought setup.py would put them there.
> 
> 
> 
> 
> 2nd option is using subversion but how do i check if i have/use apache
> 2.0 or 2.2?
> > 
> 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Creating a Scheduled Task

2008-07-12 Thread Chris

Hi,

I'm a newbie to Django, and I'm trying to find the best way to create
a recurring scheduled task. I'd like to run a script that periodically
downloads an RSS feed and updates records in the database. I can do
this "outside" Django with Cron and a script that uses the standalone
ORM, but is there any way to incorporate this into admin so I can see
what tasks are run and when?

Thanks,
Chris

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Updating Database Schema

2008-07-12 Thread Chris

What's the best way to update database schema? If I add a column to a
table in my models.py and then run "manage.py syncdb", it doesn't add
the new column in the database.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Updating Database Schema

2008-07-12 Thread Chris

On Jul 12, 3:31 pm, Jeff Anderson <[EMAIL PROTECTED]> wrote:
> Chris wrote:
> > What's the best way to update database schema? If I add a column to a
> > table in my models.py and then run "manage.py syncdb", it doesn't add
> > the new column in the database.
>
> syncdb will never issue an alter statement-- this could be devastating
> on a production server with lots of data.
>
> You have a few options:
>
> * issue the alter table command yourself
> * drop the table altogether and run syncdb again
> * check out the django-evolution project on google code. I haven't used
> it, but it is designed to handle just this.
>
> Good Luck!
>
> Jeff Anderson

Thanks. I'm not sure how an add column statement would be devastating,
but I can easily imagine how drop statements could wreak havoc.

Chris
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Accessing User Object From Template

2008-07-12 Thread Chris

According to http://www.djangoproject.com/documentation/authentication/
each template should have access to the variable "user" by default.
However, after I login, this variable doesn't seem to be defined. Is
there any special configuration required to have access to this? The
only weird thing I imagine I could be doing is using
render_to_response in my view. Would that be blocking the context from
being populated correctly?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Left Outer Join

2008-07-12 Thread Chris

I'm reasonably fluent in SQL, and while I've found Django's ORM is
great for basic CRUD operations, I'm having trouble creating joins.

For example, I have a three tables, Article, Rating, and User. Rating
stores a user's rating of a particular article. I'm trying to create a
view that lists articles, and optionally shows the current user's
rating of each article, if they've made one. To query the rating
record along with the article in SQL, this would just be a simple left
outer join. How would this be done with Django's ORM? I've reviewed
http://www.djangoproject.com/documentation/model-api/#relationships
but I don't think it covers this case.

Regards,
Chris
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Accessing User Object From Template

2008-07-12 Thread Chris

On Jul 12, 11:30 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> Are you using RequestContext, not Context, as mentioned here:

Nope, thanks for the clarification. I guess I misinterpreted the
technicality note that says that's the default.

Chris
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Template Language Design

2008-07-13 Thread Chris

Just out of curiosity, is there a reason why the templating constructs
can't evaluate arbitrary expressions? It seems terribly awkward to me
that {% if %} can only evaluate variable names, while you need the
separate operator {% ifequals %} to test for equality, and for some
reason it doesn't support {% else %}.

I had a very simple use case where I wanted to do something like:

{% if a == 1}blah{% else %}foo{% endif %}

and the closest I can get is:

{% ifequal a 1 %}blah{% endifequal %}{% ifnotequal a 1 %}foo{%
endifnotequal %}

Chris
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Template Language Design

2008-07-13 Thread Chris

Thanks for the clarifications everyone. It seems less crazy now ;)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Unique Case Sensitivity

2008-07-15 Thread Chris

I've run into a strange situation. I have a MySQL database with a
table called Feature, with a unique column called text.

Given some text, I want to save a new record if hasn't been entered,
or retrieve the existing record if it already exists. Oddly enough,
this code fails if the current text has already been entered with a
different case (e.g. 'abc' vs 'ABC').
try:
ftr = Feature(text=text)
ftr.save()
except MySQLdb.IntegrityError, e:
ftr = Feature.objects.get(text=text)

As the default behavior, this seems misleading, since whether or not
the ORM is case-sensitive, I'd expect the creation and retrieval
function to be consistent. If save() fails to insert "Abc" because
"abc" has already been inserted, then I'd expect get(text="Abc") to
return the record for "abc".

Is this the fault of Django's ORM, or some obscure MySQL setting?

Regards,
Chris
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Standard documentation method.

2008-07-18 Thread Chris

hello,
Does django have a preferred method of commenting on code in
docstrings? I notice that there is some specific ways that some
applications write documentation in their code but didn't know if
django had some kind of preferred method. I would like to be able to
parse in my code documentation on the backend using docutils but I
noticed that I get errors b/c my strings are not formatted a specific
way.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Template Hiding Strings with Non-Ascii Characters

2008-07-20 Thread Chris

Forgive the repost, but after initially seeing my original post,
Google appears to have deleted it, so here goes again.

I'm running the current trunk, and I'm seeing a strange problem. I
noticed Django's templates were occasionally displaying variables as
empty strings, when there should have been something. Then I realized,
all the strings that weren't being shown had a \x... character in
them. I can understand why these characters aren't being shown, but
why is the entire string not being shown? Shouldn't the the default
setup automatically escape or strip out these characters?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Template Hiding Strings with Non-Ascii Characters

2008-07-20 Thread Chris

I'm running the current trunk, and I'm seeing a strange problem. I
noticed Django's templates were occasionally displaying variables as
empty strings, when there should have been something. Then I realized,
all the strings that weren't being shown had a \x... character in
them. I can understand why these characters aren't being shown, but
why is the entire string not being shown? Shouldn't the the default
setup automatically escape or strip out these characters?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Streaming uploads help

2008-07-22 Thread Chris

Hello I have an image field in my photos model that has an
upload_to='event-photos/%Y/%m/%d/' variable but I am not sure how I
can reference this using streaming uploads.

before streaming uploads you could do something like:
p = Photo(**params)
p.save_photo_file(photo.filename, photo.content)

Is there a streaming uploads method that allows me to do something
simple like the above?

Right now I am simply doing this which obviously does not get the
directory structure that I want.

PATH_ROOT = os.path.join(MEDIA_ROOT, 'event-photos', ph.name)
IMAGE_PATH = os.path.join('event-photos', ph.name)
destination = open(PATH_ROOT, 'wb+')
for chunk in ph.chunks():
destination.write(chunk)
destination.close()
p = Photo(event=event)
 p.photo = IMAGE_PATH
p.save()

Is there an easier way?

Thanks in advance
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Field Instances overriding each others arguments

2018-10-18 Thread chris
Hi folks, 

I am testing and preparing a new Django package for using bleach with Text and 
Char fields in the Django ORM and with DRF. I've hit a bit of a roadblock with 
it however and it has made me take pause and wonder if I truly understand how a 
models fields are instantiated. Hopefully someone can clear this up. 

I am initialising the arguments for bleach by loading a default settings dict 
from django.conf.settings, and then checking a field_args parameter to see if 
any have been overridden for a specific field definition, like below. This is 
then used in the pre_save function to call bleach: 

class BleachedCharField(CharField): 
""" 
An enhanced CharField for sanitising input with the Python library, bleach. 
""" 

def __init__ ( self , *args , field_args= None, **kwargs): 
""" 
Initialize the BleachedCharField with default arguments, and update with called 
parameters. 

:param tags: (dict) optional bleach argument overrides, format matches 
BLEACHFIELDS defaults. 
:param args: extra args to pass to CharField __init__ 
:param kwargs: undefined args 
""" 
super (BleachedCharField , self ). __init__ (*args , **kwargs) 

self .args = settings.BLEACHFIELDS or None 

if field_args: 
if 'tags' in field_args: 
self .args[ 'tags' ] = field_args[ 'tags' ] 
if 'attributes' in field_args: 
self .args[ 'attributes' ] = field_args[ 'attributes' ] 
if 'styles' in field_args: 
self .args[ 'styles' ] = field_args[ 'styles' ] 
if 'protocols' in field_args: 
self .args[ 'protocols' ] = field_args[ 'protocols' ] 
if 'strip' in field_args: 
self .args[ 'strip' ] = field_args[ 'strip' ] 
if 'strip_comments' in field_args: 
self .args[ 'strip_comments' ] = field_args[ 'strip_comments' ] 

def pre_save ( self , model_instance , add): 
""" 
Clean text, update model and return cleaned text. 

:param model_instance: (obj) model instance 
:param add: default textfield parameter, unused 
:return : clean text as unicode 
""" 
bleached = clean( getattr (model_instance , self .attname) , ** self .args) 
setattr (model_instance , self .attname , bleached) 
return bleached 
The problem I am having is that the `self.field_args` value for all fields on a 
model seems to be the value of the last field loaded on the model. So for 
example on this model: 

class Writing(models.Model): 
""" 
Stores a single writing of a specific Form ( relation 
:model:`writings.WritingForm` ) and 
Category ( relation :model:`writings.Category` ). 
""" 

author = models.ForeignKey( 
settings.AUTH_USER_MODEL , 
on_delete =models.CASCADE , 
help_text =trans( "Author" ) 
) 

title = BleachedCharField( 
max_length = 200 , 
help_text =trans( "Title" ) 
) 

created = models.DateTimeField( 
auto_now_add = True, 
help_text =trans( "First created." ) 
) 

edited = models.DateTimeField( 
auto_now_add = True, 
help_text =trans( "Last edited." ) 
) 

description = BleachedTextField( 
blank = True, 
help_text =trans( "A short description of the writing to entice potential 
readers." ) 
) 

body = BleachedTextField( 
field_args =settings.PERMISSIVE_BLEACHFIELDS , 
help_text =trans( "The body of the writing itself." ) 
) 

writing_form = models.ForeignKey( 
WritingForm , 
on_delete =models.CASCADE , 
help_text =trans( "Primary writing form." ) 
) 

category = models.ForeignKey( 
Category , 
on_delete =models.CASCADE , 
help_text =trans( "Writing form category" ) 
) 

slug = models.SlugField( 
editable = False, 
help_text =trans( "URL and SEO friendly lower-cased string." ) , 
unique = True 
) 

comments = GenericRelation(settings.COMMENT_MODEL) 

On this model the `body` field which is the last field on the model overrides 
the self.args of all the BleachCharField and BleachedTextField instances before 
it, so they all take the same parameters. 

Am I missing something on this? Is self.args not being added to the fields, but 
to the model instance instead? Is that why the last fields settings override 
all the field settings? How should I be doing this to avoid this issue? 



Cheers, 

Chris Routh 

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1363577083.40556.1539874709796.JavaMail.zimbra%40routh.io.
For more options, visit https://groups.google.com/d/optout.


Re: Field Instances overriding each others arguments

2018-10-18 Thread chris
Got an answer on StackOverflow 
https://stackoverflow.com/questions/52878934/django-field-instances-overriding-each-others-arguments/52879102#52879102
 

I was linking to a mutable dict instead of copying it. That was a bit dumb. 


Cheers, 

Chris Routh 


From: ch...@routh.io 
To: "django-users"  
Sent: Thursday, October 18, 2018 7:58:29 AM 
Subject: Field Instances overriding each others arguments 

Hi folks, 

I am testing and preparing a new Django package for using bleach with Text and 
Char fields in the Django ORM and with DRF. I've hit a bit of a roadblock with 
it however and it has made me take pause and wonder if I truly understand how a 
models fields are instantiated. Hopefully someone can clear this up. 

I am initialising the arguments for bleach by loading a default settings dict 
from django.conf.settings, and then checking a field_args parameter to see if 
any have been overridden for a specific field definition, like below. This is 
then used in the pre_save function to call bleach: 

class BleachedCharField(CharField): 
""" 
An enhanced CharField for sanitising input with the Python library, bleach. 
""" 

def __init__ ( self , *args , field_args= None, **kwargs): 
""" 
Initialize the BleachedCharField with default arguments, and update with called 
parameters. 

:param tags: (dict) optional bleach argument overrides, format matches 
BLEACHFIELDS defaults. 
:param args: extra args to pass to CharField __init__ 
:param kwargs: undefined args 
""" 
super (BleachedCharField , self ). __init__ (*args , **kwargs) 

self .args = settings.BLEACHFIELDS or None 

if field_args: 
if 'tags' in field_args: 
self .args[ 'tags' ] = field_args[ 'tags' ] 
if 'attributes' in field_args: 
self .args[ 'attributes' ] = field_args[ 'attributes' ] 
if 'styles' in field_args: 
self .args[ 'styles' ] = field_args[ 'styles' ] 
if 'protocols' in field_args: 
self .args[ 'protocols' ] = field_args[ 'protocols' ] 
if 'strip' in field_args: 
self .args[ 'strip' ] = field_args[ 'strip' ] 
if 'strip_comments' in field_args: 
self .args[ 'strip_comments' ] = field_args[ 'strip_comments' ] 

def pre_save ( self , model_instance , add): 
""" 
Clean text, update model and return cleaned text. 

:param model_instance: (obj) model instance 
:param add: default textfield parameter, unused 
:return : clean text as unicode 
""" 
bleached = clean( getattr (model_instance , self .attname) , ** self .args) 
setattr (model_instance , self .attname , bleached) 
return bleached 
The problem I am having is that the `self.field_args` value for all fields on a 
model seems to be the value of the last field loaded on the model. So for 
example on this model: 

class Writing(models.Model): 
""" 
Stores a single writing of a specific Form ( relation 
:model:`writings.WritingForm` ) and 
Category ( relation :model:`writings.Category` ). 
""" 

author = models.ForeignKey( 
settings.AUTH_USER_MODEL , 
on_delete =models.CASCADE , 
help_text =trans( "Author" ) 
) 

title = BleachedCharField( 
max_length = 200 , 
help_text =trans( "Title" ) 
) 

created = models.DateTimeField( 
auto_now_add = True, 
help_text =trans( "First created." ) 
) 

edited = models.DateTimeField( 
auto_now_add = True, 
help_text =trans( "Last edited." ) 
) 

description = BleachedTextField( 
blank = True, 
help_text =trans( "A short description of the writing to entice potential 
readers." ) 
) 

body = BleachedTextField( 
field_args =settings.PERMISSIVE_BLEACHFIELDS , 
help_text =trans( "The body of the writing itself." ) 
) 

writing_form = models.ForeignKey( 
WritingForm , 
on_delete =models.CASCADE , 
help_text =trans( "Primary writing form." ) 
) 

category = models.ForeignKey( 
Category , 
on_delete =models.CASCADE , 
help_text =trans( "Writing form category" ) 
) 

slug = models.SlugField( 
editable = False, 
help_text =trans( "URL and SEO friendly lower-cased string." ) , 
unique = True 
) 

comments = GenericRelation(settings.COMMENT_MODEL) 

On this model the `body` field which is the last field on the model overrides 
the self.args of all the BleachCharField and BleachedTextField instances before 
it, so they all take the same parameters. 

Am I missing something on this? Is self.args not being added to the fields, but 
to the model instance instead? Is that why the last fields settings override 
all the field settings? How should I be doing this to avoid this issue? 



Cheers, 

Chris Routh 


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group. 
To unsubscribe from this group and stop receiving ema

Channels: about max message size

2018-10-23 Thread Chris
I use Channels & websockets for my webapp's "export data" functionality, 
since it can take a long time to generate the file (more than 30 seconds). 
In general this works fine, even for large downloads (several MB), but I 
have seen several cases on Heroku where the browser never receives the 
message with the file, even though debugging shows that 
JsonWebsocketConsumer.send was called as expected.

I found this Github issue  that 
says the message limit is 1 MB (or maybe 256 kb). My questions:

- Where is this limit defined? I searched the source of Channels and 
Daphne. I'm trying to figure out where the failure is happening -- in the 
worker, Daphne, or Redis.
- What happens if the limit is exceeded? Is an exception raised? (Because 
in my case it fails silently.)
- Is there really a 1 MB limit? Because it seems I have been able to send 
files larger than that using channels/asgi_redis (unfortunately I'm still 
on channels 0.17.3, can't upgrade yet because of a Twisted bug).

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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/da8fc1ab-8a75-4504-ab3a-6ab31cfd132e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Channels: about max message size

2018-10-24 Thread Chris
Thank you Andrew. Hope I can upgrade soon to get the Channels 2.X 
awesomeness :)

On Wednesday, October 24, 2018 at 2:08:19 AM UTC+9, Andrew Godwin wrote:
>
> Hmm, it's possible the 0.x series didn't have response streaming for files 
> so there'd be a limit, but I honestly can't remember, that was years ago. 
> There's really not much I can do other than recommending an upgrade to 
> something vaguely recent.
>
> Also make sure Heroku is not cutting you off with a request timeout or 
> something.
>
> Andrew
>
> On Tue, Oct 23, 2018 at 5:38 AM Chris > 
> wrote:
>
>> I use Channels & websockets for my webapp's "export data" functionality, 
>> since it can take a long time to generate the file (more than 30 seconds). 
>> In general this works fine, even for large downloads (several MB), but I 
>> have seen several cases on Heroku where the browser never receives the 
>> message with the file, even though debugging shows that 
>> JsonWebsocketConsumer.send was called as expected.
>>
>> I found this Github issue <https://github.com/django/channels/issues/11> 
>> that 
>> says the message limit is 1 MB (or maybe 256 kb). My questions:
>>
>> - Where is this limit defined? I searched the source of Channels and 
>> Daphne. I'm trying to figure out where the failure is happening -- in the 
>> worker, Daphne, or Redis.
>> - What happens if the limit is exceeded? Is an exception raised? (Because 
>> in my case it fails silently.)
>> - Is there really a 1 MB limit? Because it seems I have been able to send 
>> files larger than that using channels/asgi_redis (unfortunately I'm still 
>> on channels 0.17.3, can't upgrade yet because of a Twisted bug).
>>
>> Thanks!
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/da8fc1ab-8a75-4504-ab3a-6ab31cfd132e%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/da8fc1ab-8a75-4504-ab3a-6ab31cfd132e%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/174c7388-be0d-477d-9b6d-803b04b5626e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Cannot get Django test migrations to detect test models.py

2018-11-03 Thread chris
Hi folks, I'm trying to build a test suite for a django plugin for a field. 
To test the field I need to have a test model, but since my django app does 
not provide models, and I have the model in the /tests/models.py it's not 
detecting the model when the test db migrations are applied. I saw some 
suggestions on stack overflow to add the test app to the INSTALLED_APPS in 
the test app, however that causes an 
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. error, 
which I imagine is caused by the tests app not being a full blown app. 
What's the proper solution for Django 2.0+ ? I'd prefer not to use the fake 
models solution as I plan to open source the module and want the field 
tested against a real db on Django 2.0 and 2.1. 

Source is here: https://gitlab.routh.io/open-source/django-bleachfields

Test failures and attempted configurations can be seen in the CI pipeline 
and commit history.

Hoping someone can lend their insights.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d525bd73-0db8-4d17-b5b8-254461a9a533%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Cannot get Django test migrations to detect test models.py

2018-11-05 Thread chris
I'm not sure you understood the question. 


From: "amit pant"  
To: "django-users"  
Sent: Monday, November 5, 2018 2:24:51 AM 
Subject: Re: Cannot get Django test migrations to detect test models.py 

can you register your model in admin.py? 
If not then go for it. 

On Sun 4 Nov, 2018, 12:10 AM , < [ mailto:ch...@routh.io | ch...@routh.io ] > 
wrote: 



Hi folks, I'm trying to build a test suite for a django plugin for a field. To 
test the field I need to have a test model, but since my django app does not 
provide models, and I have the model in the /tests/models.py it's not detecting 
the model when the test db migrations are applied. I saw some suggestions on 
stack overflow to add the test app to the INSTALLED_APPS in the test app, 
however that causes an django.core.exceptions.AppRegistryNotReady: Apps aren't 
loaded yet. error, which I imagine is caused by the tests app not being a full 
blown app. What's the proper solution for Django 2.0+ ? I'd prefer not to use 
the fake models solution as I plan to open source the module and want the field 
tested against a real db on Django 2.0 and 2.1. 

Source is here: [ https://gitlab.routh.io/open-source/django-bleachfields | 
https://gitlab.routh.io/open-source/django-bleachfields ] 

Test failures and attempted configurations can be seen in the CI pipeline and 
commit history. 

Hoping someone can lend their insights. 


-- 
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 [ mailto:django-users+unsubscr...@googlegroups.com | 
django-users+unsubscr...@googlegroups.com ] . 
To post to this group, send email to [ mailto:django-users@googlegroups.com | 
django-users@googlegroups.com ] . 
Visit this group at [ https://groups.google.com/group/django-users | 
https://groups.google.com/group/django-users ] . 
To view this discussion on the web visit [ 
https://groups.google.com/d/msgid/django-users/d525bd73-0db8-4d17-b5b8-254461a9a533%40googlegroups.com?utm_medium=email&utm_source=footer
 | 
https://groups.google.com/d/msgid/django-users/d525bd73-0db8-4d17-b5b8-254461a9a533%40googlegroups.com
 ] . 
For more options, visit [ https://groups.google.com/d/optout | 
https://groups.google.com/d/optout ] . 





-- 
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 [ mailto:django-users+unsubscr...@googlegroups.com | 
django-users+unsubscr...@googlegroups.com ] . 
To post to this group, send email to [ mailto:django-users@googlegroups.com | 
django-users@googlegroups.com ] . 
Visit this group at [ https://groups.google.com/group/django-users | 
https://groups.google.com/group/django-users ] . 
To view this discussion on the web visit [ 
https://groups.google.com/d/msgid/django-users/CAF2Ah_E4d96VrDsnamQ1DJk9tzBgFG7EgpH7RNsEjKm-B-vG9Q%40mail.gmail.com?utm_medium=email&utm_source=footer
 | 
https://groups.google.com/d/msgid/django-users/CAF2Ah_E4d96VrDsnamQ1DJk9tzBgFG7EgpH7RNsEjKm-B-vG9Q%40mail.gmail.com
 ] . 
For more options, visit [ https://groups.google.com/d/optout | 
https://groups.google.com/d/optout ] . 

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/368149463.10493.1541425347709.JavaMail.zimbra%40routh.io.
For more options, visit https://groups.google.com/d/optout.


Re: Cannot get Django test migrations to detect test models.py

2018-11-05 Thread chris
I am not sure you understood. I am doing testing, and this is a model that is 
only for tests. I am attempting to achieve the test-only models solution 
outlined here: 

https://code.djangoproject.com/ticket/7835#comment:24 

Also outlined in the first paragraph of this accepted answer on stack overflow: 

https://stackoverflow.com/questions/502916/django-how-to-create-a-model-dynamically-just-for-testing?rq=1
 


app/tests/models.py or putting models in app/tests.py should result in the 
model being detected and migrated in the test database, but the model is never 
detected, so the tests fail when they are run because the tables are missing. 


From: "Phako Perez" <13.phak...@gmail.com> 
To: "django-users"  
Sent: Saturday, November 3, 2018 7:06:19 PM 
Subject: Re: Cannot get Django test migrations to detect test models.py 

I can suggest to use different name for your test app, as directory test is 
used by Django for actual test your application, maybe is that the reason your 
app is failing 

Sent from my iPhone 

On Nov 3, 2018, at 12:40 PM, [ mailto:ch...@routh.io | ch...@routh.io ] wrote: 




Hi folks, I'm trying to build a test suite for a django plugin for a field. To 
test the field I need to have a test model, but since my django app does not 
provide models, and I have the model in the /tests/models.py it's not detecting 
the model when the test db migrations are applied. I saw some suggestions on 
stack overflow to add the test app to the INSTALLED_APPS in the test app, 
however that causes an django.core.exceptions.AppRegistryNotReady: Apps aren't 
loaded yet. error, which I imagine is caused by the tests app not being a full 
blown app. What's the proper solution for Django 2.0+ ? I'd prefer not to use 
the fake models solution as I plan to open source the module and want the field 
tested against a real db on Django 2.0 and 2.1. 

Source is here: [ https://gitlab.routh.io/open-source/django-bleachfields | 
https://gitlab.routh.io/open-source/django-bleachfields ] 

Test failures and attempted configurations can be seen in the CI pipeline and 
commit history. 

Hoping someone can lend their insights. 


-- 
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 [ mailto:django-users+unsubscr...@googlegroups.com | 
django-users+unsubscr...@googlegroups.com ] . 
To post to this group, send email to [ mailto:django-users@googlegroups.com | 
django-users@googlegroups.com ] . 
Visit this group at [ https://groups.google.com/group/django-users | 
https://groups.google.com/group/django-users ] . 
To view this discussion on the web visit [ 
https://groups.google.com/d/msgid/django-users/d525bd73-0db8-4d17-b5b8-254461a9a533%40googlegroups.com?utm_medium=email&utm_source=footer
 | 
https://groups.google.com/d/msgid/django-users/d525bd73-0db8-4d17-b5b8-254461a9a533%40googlegroups.com
 ] . 
For more options, visit [ https://groups.google.com/d/optout | 
https://groups.google.com/d/optout ] . 




-- 
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 [ mailto:django-users+unsubscr...@googlegroups.com | 
django-users+unsubscr...@googlegroups.com ] . 
To post to this group, send email to [ mailto:django-users@googlegroups.com | 
django-users@googlegroups.com ] . 
Visit this group at [ https://groups.google.com/group/django-users | 
https://groups.google.com/group/django-users ] . 
To view this discussion on the web visit [ 
https://groups.google.com/d/msgid/django-users/C71D5DB6-C733-4265-9B4C-EE05CEC6ED52%40gmail.com?utm_medium=email&utm_source=footer
 | 
https://groups.google.com/d/msgid/django-users/C71D5DB6-C733-4265-9B4C-EE05CEC6ED52%40gmail.com
 ] . 
For more options, visit [ https://groups.google.com/d/optout | 
https://groups.google.com/d/optout ] . 

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1144431128.10508.1541425519599.JavaMail.zimbra%40routh.io.
For more options, visit https://groups.google.com/d/optout.


channels_redis & async_to_sync performance problem

2020-03-29 Thread Chris
Hello,

I have a worker process that uses async_to_sync(group_send) to send 
messages to my Channels consumers. The worker process is a simple 
long-running synchronous loop (not based on Django Channels) that is 
started via a Django management command.

When I use runserver and the in-memory channel layer, performance is great. 
But when I use channels_redis in production, each call to group_send takes 
2 seconds, because each time it needs to create a new redis connection. 
Here is the call stack:

  File "c:\my_project\core\my_project\channels\utils.py", line 14, in 
sync_group_send_wrapper
return _sync_group_send(group, {'type': type, **event})
  File "c:\my_project\ve-dj2\lib\site-packages\asgiref\sync.py", line 79, in 
__call__
return call_result.result()
  File 
"C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\concurrent\futures\_base.py"
, line 428, in result
return self.__get_result()
  File 
"C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\concurrent\futures\_base.py"
, line 384, in __get_result
raise self._exception
  File "c:\my_project\ve-dj2\lib\site-packages\asgiref\sync.py", line 98, in 
main_wrap
result = await self.awaitable(*args, **kwargs)
  File "c:\my_project\ve-dj2\lib\site-packages\channels_redis\core.py", 
line 625, in group_send
async with self.connection(self.consistent_hash(group)) as connection:
  File "c:\my_project\ve-dj2\lib\site-packages\channels_redis\core.py", 
line 839, in __aenter__
self.conn = await self.pool.pop()
  File "c:\my_project\ve-dj2\lib\site-packages\channels_redis\core.py", 
line , in pop
conns.append(await aioredis.create_redis(**self.host, loop=loop))

This is happening because the connection is deleted after each call to 
async_to_sync:

  File "c:\my_project\core\my_project\channels\utils.py", line 14, in 
sync_group_send_wrapper
return _sync_group_send(group, {'type': type, **event})
  File "c:\my_project\ve-dj2\lib\site-packages\asgiref\sync.py", line 71, in 
__call__
loop.close()
  File "c:\my_project\ve-dj2\lib\site-packages\channels_redis\core.py", 
line 32, in _wrapper
self.run_until_complete(pool.close_loop(self))
  File 
"C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\asyncio\base_events.py"
, line 579, in run_until_complete
return future.result()
  File "c:\my_project\ve-dj2\lib\site-packages\channels_redis\core.py", 
line , in close_loop
del self.conn_map[loop]

When async_to_sync is called from a synchronous Django view, the connection 
is NOT deleted. That's because in my worker process, 
self.main_event_loop.is_running() is False, but in my Django views, it's 
True. That affects this if-statement in async_to_sync.__call__:

if not (self.main_event_loop and self.main_event_loop.is_running()):
# Redis connection gets deleted inside here...

So, how could I solve this? This may be an obvious question but I don't 
know asyncio well; I just want to get some guidance before I spend too much 
time looking in the wrong direction.

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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/afa1c36a-bdb5-40b7-a602-ee20d7949ac2%40googlegroups.com.


Django TidyFields

2019-04-24 Thread chris
Hi folks, 

This is a short message to announce the first release of Django TidyFields: [ 
https://pypi.org/project/django-tidyfields/ | 
https://pypi.org/project/django-tidyfields/ ] 

Django TidyFields is a set of text input fields, (currently CharField and 
TextField are subclassed) which sanitize user input on model save. This allows 
them to work with Django views or apis, including Django Rest Framework. 

The fields leverage lxml's Cleaner under the hood, so they are quite 
configurable for your needs. The fields are also tested against the OWASP XSS 
filter evasion cheat sheet methods. In the initial release 30 different attacks 
are tested, and the rest will be added in the next version. 

Future plans include adding form fields with integration support for WYSIWYG 
libraries like django-summernote. 

I hope you find the module useful, 

Chris Routh 
Github: Routhinator 

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/380841987.20542.1556119040704.JavaMail.zimbra%40routh.io.
For more options, visit https://groups.google.com/d/optout.


Channels: can I run a worker in the same process?

2019-06-07 Thread Chris
I'm getting started with Channels 2.x. In my web app, certain actions take 
more than 30 seconds to complete, so rather than doing it synchronously in 
the request, we do the processing in the background. It seems that any 
background task requires ChannelNameRouter and a separate runworker 
process. But I am wondering if it's possible to do it in the same process, 
because:


- Background tasks are only run occasionally, so most of the time runworker 
will be idle and consuming RAM on resource-constrained servers.
- Many people use my webapp with runserver, and I want to use the in-memory 
channel layer rather than requiring them to install Redis

I am thinking of an option like this:
(a) Start a channels.worker.Worker in a thread, like previous versions of 
Channels did in runserver. When I tried this I got an error about running 
event loops inside a thread (I cannot locate the error message at the 
moment).
(b) Instantiate the background task's consumer as a singleton in the daphne 
process and send messages to its channel name, so it works like any other 
consumer.

Any ideas?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/02243277-c17d-48c7-90cf-74f9096638dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


<    1   2   3   4   5   6   7   8   9   10   >