Re: Django development with iPad as target platform?

2011-05-27 Thread Russell Keith-Magee
On Fri, May 27, 2011 at 10:25 PM, Shawn Milochik  wrote:
> On 05/27/2011 10:21 AM, Thomas Weholt wrote:
>>
>> I just got my hands on an iPad and was wondering if anybody has done
>> any django development where the iPad was the target
>> platform/browser/client?
>>
>> Thanks in advance and expect some django-app aimed at ipad in the near
>> future ;-).
>>
> As someone who had an iPad for over a year, I'd say there there's really
> nothing to "target." You have a very usable browser and screen size, and I
> didn't have problems with any sites that I can think of.

Whether there is something to target depends entirely on the site
you're writing. There are three *major* differences between an iPad
interface and a browser interface that I can think of off the top of
my head:

 * iPads don't have a native concept of "hover" or "mouseover"
(because your finger can't hover, and you don't have a mouse)

 * iPad's have touch events, not mouse events, so anything triggering
onMouseDown/Up etc, or using drag and drop won't work.

 * No support for Flash.

Now, for many sites, this doesn't matter. A list of clickable links is
a list of clickable links, no matter where it's rendered. However, if
you've got dense IA or you want to deliver a web app with a rich UI
experience, these differences are huge.

And to answer the OP's question -- Yes, I've done some iPad app
development (both native app and web); as far as Django is concerned,
the iPad is just a fancy browser. The tech decisions you have to make
are entirely client side (JS/CSS frameworks and so on), not server
side.

Yours,
Russ Magee %-)

-- 
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: primary key auto increment with PostgreSQL and non Django standard column name

2011-05-27 Thread Naoko Reeves
I see if column is set to AutoField then Django won't send INSERT poll_key
as null.
Now my problem is that it doesn't return newly assigned primary key value
for me if primary key name is _key instead of _id
It looks as if sequence name is not understood correctly.
Could you tell me if
1) I need to change sequence name to something else? Currently it is
poll_key_seq
2) Is there a way to specify the sequence name?


class Poll(models.Model):
poll_key = models.AutoField(primary_key=True)
poll_question = models.CharField(max_length=200, default='')

class Poll2(models.Model):
poll2_id = models.AutoField(primary_key=True)
poll2_question = models.CharField(max_length=200, default='')

>>> from mysite.polls.models import Poll2
>>> p3 = Poll2(poll2_question='3')
>>> p3.save()
>>> p3.pk
2L
>>> p4 = Poll2(poll2_question='4')
>>> p4.save()
>>> p4.pk
3L
>>> from mysite.polls.models import Poll
>>> p5 = Poll(poll_question='5')
>>> p5.save()
>>> print p5.pk
None


On 5/27/11 5:31 PM, "Casey Greene"  wrote:

> Doesn't autofield with primary_key=True handle this for you (instead of
> making it an IntegerField):
> 
> https://docs.djangoproject.com/en/1.3/ref/models/fields/#autofield
> 
> Hope this helps!
> Casey
> 
> On 05/27/2011 07:22 PM, Naoko Reeves wrote:
>> Hi, I have a Django newbie question.
>> My goal is to auto increment primary key with non Django standard column
>> name.
>> We are converting from existing database and primary key schema is
>> "tablename_key" and not "id".
>> I googled it and end up reaching to this ticket:
>> https://code.djangoproject.com/ticket/13295
>> So I understand that there is work in progress but I wanted find work
>> around..
>> 
>> 1. My first try was to let postgres handle it.
>> 
>> my postgreSQL table looks like this:
>> 
>> CREATE TABLE poll
>> (
>>poll_key integer NOT NULL DEFAULT nextval('poll_key_seq'::regclass),
>>poll_question character varying(200) NOT NULL,
>>poll_pub_date timestamp with time zone NOT NULL,
>>CONSTRAINT poll_pkey PRIMARY KEY (poll_key)
>> )
>> 
>> My model look like this:
>> class Poll(models.Model):
>>  poll_key = models.IntegerField(primary_key=True)
>>  poll_question = models.CharField(max_length=200, default='')
>>  poll_pub_date = models.DateTimeField('date published',
>> default=datetime.date.today())
>>  class Meta:
>>  db_table = u'poll'
>> 
>> I was hoping that with this, I could
>> p = Poll(poll_question="Question 1?")
>> p.save()
>> 
>> but this fails because Django is actually sending the following statement:
>> INSERT INTO "poll" ("poll_key", "poll_question", "poll_pub_date")
>> VALUES (NULL, 'Question 1?', NULL)
>> 
>> 
>> 2. My Second attempt is then to add default to model
>> 
>> Created a function to return sequence value
>> from django.db import connection
>> def c_get_next_key(seq_name):
>> """ return next value of sequence """
>>  c = connection.cursor()
>>  c.execute("SELECT nextval('%s')" % seq_name)
>>  row = c.fetchone()
>>  return int(row[0])
>> 
>> Calling like below works just fine. Everytime I call it, I get new number.
>> c_get_next_key('poll_key_seq')
>> 
>> Then I modify Poll_key in Poll model as follows:
>> Poll_key = models.IntegerField(primary_key=True,
>> default=c_get_next_key('poll_key_seq'))
>> 
>> I went to Django Shell and created first record.
>> p1 = Poll(poll_question="P1")
>> p1.poll_key
>> # this will return let's say 37
>> p1.save()
>> # saves just fine.
>> 
>> # instantiating new object
>> p2 = Poll(poll_question="P2")
>> p2.poll_key
>> # this also return 37.
>> 
>> I know I must be doing something wrong... but could you pint me to right
>> direction? I am expecting p2.poll_key to return 38.
>> Thank you very much for your help in advance.
>> 
>> Naoko
>> 
>> 
>> 
>> 
>> 
>> --
>> 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.


-- 
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: Why self-defined session_key got changed when save in DB?

2011-05-27 Thread Jimmy
btw, I use Django-1.3. Is this a bug?

On May 28, 11:00 am, Jimmy  wrote:
> Hi,
>
> I have following code to set self-defined session_key:
>
> >>> from django.contrib.sessions.backends.db import SessionStore
> >>> from django.contrib.sessions.models import Session
> >>> a = SessionStore(session_key="fwefwejfo3j20jf02jnfweojfeo")
> >>> a.save()
> >>> a.session_key
>
> 'a6e020a64789b5644e923c85b80a1d0b'
>
> Why the session_key got changed after saved in DB? Where is my defined
> session_key?

-- 
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: primary key auto increment with PostgreSQL and non Django standard column name

2011-05-27 Thread Naoko Reeves
Casey,
Thank you for your help! As Casey suggested by changing the column
definition of model to:

poll_key = models.AutoField(primary_key=True)

Now create INSERT statement as follows:
 INSERT INTO "poll" ("poll_question", "poll_pub_date") VALUES ('Question!',
'2011-05-27 00:00:00')

With PostgreSQL Schema:
poll_key integer NOT NULL DEFAULT nextval('poll_key_seq'::regclass),

It achieve the goal.
Now question: Documentation indicates that " This is an auto-incrementing
primary key.". This suggest me that Django will create INSERT statement with
poll_key with next sequence value. Am I understanding incorrectly?

Thank you again for your advice in advance.



On 5/27/11 5:31 PM, "Casey Greene"  wrote:

> Doesn't autofield with primary_key=True handle this for you (instead of
> making it an IntegerField):
> 
> https://docs.djangoproject.com/en/1.3/ref/models/fields/#autofield
> 
> Hope this helps!
> Casey
> 
> On 05/27/2011 07:22 PM, Naoko Reeves wrote:
>> Hi, I have a Django newbie question.
>> My goal is to auto increment primary key with non Django standard column
>> name.
>> We are converting from existing database and primary key schema is
>> "tablename_key" and not "id".
>> I googled it and end up reaching to this ticket:
>> https://code.djangoproject.com/ticket/13295
>> So I understand that there is work in progress but I wanted find work
>> around..
>> 
>> 1. My first try was to let postgres handle it.
>> 
>> my postgreSQL table looks like this:
>> 
>> CREATE TABLE poll
>> (
>>poll_key integer NOT NULL DEFAULT nextval('poll_key_seq'::regclass),
>>poll_question character varying(200) NOT NULL,
>>poll_pub_date timestamp with time zone NOT NULL,
>>CONSTRAINT poll_pkey PRIMARY KEY (poll_key)
>> )
>> 
>> My model look like this:
>> class Poll(models.Model):
>>  poll_key = models.IntegerField(primary_key=True)
>>  poll_question = models.CharField(max_length=200, default='')
>>  poll_pub_date = models.DateTimeField('date published',
>> default=datetime.date.today())
>>  class Meta:
>>  db_table = u'poll'
>> 
>> I was hoping that with this, I could
>> p = Poll(poll_question="Question 1?")
>> p.save()
>> 
>> but this fails because Django is actually sending the following statement:
>> INSERT INTO "poll" ("poll_key", "poll_question", "poll_pub_date")
>> VALUES (NULL, 'Question 1?', NULL)
>> 
>> 
>> 2. My Second attempt is then to add default to model
>> 
>> Created a function to return sequence value
>> from django.db import connection
>> def c_get_next_key(seq_name):
>> """ return next value of sequence """
>>  c = connection.cursor()
>>  c.execute("SELECT nextval('%s')" % seq_name)
>>  row = c.fetchone()
>>  return int(row[0])
>> 
>> Calling like below works just fine. Everytime I call it, I get new number.
>> c_get_next_key('poll_key_seq')
>> 
>> Then I modify Poll_key in Poll model as follows:
>> Poll_key = models.IntegerField(primary_key=True,
>> default=c_get_next_key('poll_key_seq'))
>> 
>> I went to Django Shell and created first record.
>> p1 = Poll(poll_question="P1")
>> p1.poll_key
>> # this will return let's say 37
>> p1.save()
>> # saves just fine.
>> 
>> # instantiating new object
>> p2 = Poll(poll_question="P2")
>> p2.poll_key
>> # this also return 37.
>> 
>> I know I must be doing something wrong... but could you pint me to right
>> direction? I am expecting p2.poll_key to return 38.
>> Thank you very much for your help in advance.
>> 
>> Naoko
>> 
>> 
>> 
>> 
>> 
>> --
>> 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.


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



Why self-defined session_key got changed when save in DB?

2011-05-27 Thread Jimmy
Hi,

I have following code to set self-defined session_key:

>>> from django.contrib.sessions.backends.db import SessionStore
>>> from django.contrib.sessions.models import Session
>>> a = SessionStore(session_key="fwefwejfo3j20jf02jnfweojfeo")
>>> a.save()
>>> a.session_key
'a6e020a64789b5644e923c85b80a1d0b'

Why the session_key got changed after saved in DB? Where is my defined
session_key?


-- 
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: django-cms and photologue

2011-05-27 Thread Venkatraman S
On Fri, May 27, 2011 at 5:32 PM, Dave Sayer  wrote:

>
> I have a question relating to integrating django-photologue with
> django-cms. I have added the cmsplugin-photologue app and am now
> attempting to add the relevant tags to my templates. The trouble is,
> is that I can't seem to find the correct tags for getting the relevant
> data from photologue. Having spent some time googling and looking
> through the docs, I have come no closer to an answer. I just want to
> display a photo that's been attached to a page. I thought it would be
> simple...perhaps it's a wood for the trees moment but i'd really
> appreciate some help.
>


Not sure, i have used photologue as an addon in my app and it worked fine;
is the integration point for the cms you have mentioned different?

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



Installing Django on Ubuntu

2011-05-27 Thread DogGoesOut
Hey, can anyone help me out? For some reason, django is not as easy as
it would appear to install on my ubuntu laptop. Here are the stats:
I'm running Ubuntu 10.10 Maverick Meerkat, and have Python 2.6
installed already,

So far, I've installed a subversion successfully, and am attempting to
create a symbolic link from django to python:

ln: creating symbolic link `/usr/local/bin/django-admin.py': File
exists
kyle@kyle-HP-Compaq-nx9420-GU760US-ABA:~$ cd ~/sites/dev
bash: cd: /home/kyle/sites/dev: No such file or directory
kyle@kyle-HP-Compaq-nx9420-GU760US-ABA:~$ python /path/to/django-trunk/
django/bin/django-admin.py startproject djangoblog
python: can't open file '/path/to/django-trunk/django/bin/django-
admin.py': [Errno 2] No such file or directory
kyle@kyle-HP-Compaq-nx9420-GU760US-ABA:~$ python /usr/local/bin/django-
admin.py startproject djangoblog
python: can't open file '/usr/local/bin/django-admin.py': [Errno 2] No
such file or directory
kyle@kyle-HP-Compaq-nx9420-GU760US-ABA:~$

Ignoring the middle (which included a typo or two) there's a statement
at the end of this code that makes no sense to me. The third line up
from the bottom, calls the file from the first line

 /usr/local/bin/django-admin.py

In the first line, this file is stated to exist. In the error message,
the computer states that it can't open the same file, and that no such
file or directory exists. This seems self-contradictory, and I'm not
sure where to go from here, as my python interpreter cannot understand
django yet. Any advice would be very much appreciated!

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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: primary key auto increment with PostgreSQL and non Django standard column name

2011-05-27 Thread Casey Greene
Doesn't autofield with primary_key=True handle this for you (instead of 
making it an IntegerField):


https://docs.djangoproject.com/en/1.3/ref/models/fields/#autofield

Hope this helps!
Casey

On 05/27/2011 07:22 PM, Naoko Reeves wrote:

Hi, I have a Django newbie question.
My goal is to auto increment primary key with non Django standard column
name.
We are converting from existing database and primary key schema is
"tablename_key" and not "id".
I googled it and end up reaching to this ticket:
https://code.djangoproject.com/ticket/13295
So I understand that there is work in progress but I wanted find work
around..

1. My first try was to let postgres handle it.

my postgreSQL table looks like this:

CREATE TABLE poll
(
   poll_key integer NOT NULL DEFAULT nextval('poll_key_seq'::regclass),
   poll_question character varying(200) NOT NULL,
   poll_pub_date timestamp with time zone NOT NULL,
   CONSTRAINT poll_pkey PRIMARY KEY (poll_key)
)

My model look like this:
class Poll(models.Model):
 poll_key = models.IntegerField(primary_key=True)
 poll_question = models.CharField(max_length=200, default='')
 poll_pub_date = models.DateTimeField('date published',
default=datetime.date.today())
 class Meta:
 db_table = u'poll'

I was hoping that with this, I could
p = Poll(poll_question="Question 1?")
p.save()

but this fails because Django is actually sending the following statement:
INSERT INTO "poll" ("poll_key", "poll_question", "poll_pub_date")
VALUES (NULL, 'Question 1?', NULL)


2. My Second attempt is then to add default to model

Created a function to return sequence value
from django.db import connection
def c_get_next_key(seq_name):
""" return next value of sequence """
 c = connection.cursor()
 c.execute("SELECT nextval('%s')" % seq_name)
 row = c.fetchone()
 return int(row[0])

Calling like below works just fine. Everytime I call it, I get new number.
c_get_next_key('poll_key_seq')

Then I modify Poll_key in Poll model as follows:
Poll_key = models.IntegerField(primary_key=True,
default=c_get_next_key('poll_key_seq'))

I went to Django Shell and created first record.
p1 = Poll(poll_question="P1")
p1.poll_key
# this will return let's say 37
p1.save()
# saves just fine.

# instantiating new object
p2 = Poll(poll_question="P2")
p2.poll_key
# this also return 37.

I know I must be doing something wrong... but could you pint me to right
direction? I am expecting p2.poll_key to return 38.
Thank you very much for your help in advance.

Naoko





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


--
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: Django development with iPad as target platform?

2011-05-27 Thread javatina
> The only thing I wish sites would do is to STOP redirecting my phones
> and tablets to their "mobile version." I hate that.

Can you please explain why? I understand that that may be true for
iPad, but for the phones?

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



primary key auto increment with PostgreSQL and non Django standard column name

2011-05-27 Thread Naoko Reeves
Hi, I have a Django newbie question.
My goal is to auto increment primary key with non Django standard column
name.
We are converting from existing database and primary key schema is
"tablename_key" and not "id".
I googled it and end up reaching to this ticket:
https://code.djangoproject.com/ticket/13295
So I understand that there is work in progress but I wanted find work
around..

1. My first try was to let postgres handle it.

my postgreSQL table looks like this:

CREATE TABLE poll
(
  poll_key integer NOT NULL DEFAULT nextval('poll_key_seq'::regclass),
  poll_question character varying(200) NOT NULL,
  poll_pub_date timestamp with time zone NOT NULL,
  CONSTRAINT poll_pkey PRIMARY KEY (poll_key)
)

My model look like this:
class Poll(models.Model):
poll_key = models.IntegerField(primary_key=True)
poll_question = models.CharField(max_length=200, default='')
poll_pub_date = models.DateTimeField('date published',
default=datetime.date.today())
class Meta:
db_table = u'poll'

I was hoping that with this, I could
p = Poll(poll_question="Question 1?")
p.save()

but this fails because Django is actually sending the following statement:
INSERT INTO "poll" ("poll_key", "poll_question", "poll_pub_date")
VALUES (NULL, 'Question 1?', NULL)


2. My Second attempt is then to add default to model

Created a function to return sequence value
from django.db import connection
def c_get_next_key(seq_name):
""" return next value of sequence """
c = connection.cursor()
c.execute("SELECT nextval('%s')" % seq_name)
row = c.fetchone()
return int(row[0])

Calling like below works just fine. Everytime I call it, I get new number.
c_get_next_key('poll_key_seq')

Then I modify Poll_key in Poll model as follows:
Poll_key = models.IntegerField(primary_key=True,
default=c_get_next_key('poll_key_seq'))

I went to Django Shell and created first record.
p1 = Poll(poll_question="P1")
p1.poll_key
# this will return let's say 37
p1.save()
# saves just fine.

# instantiating new object
p2 = Poll(poll_question="P2")
p2.poll_key
# this also return 37.

I know I must be doing something wrong... but could you pint me to right
direction? I am expecting p2.poll_key to return 38.
Thank you very much for your help in advance.

Naoko

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



Auditing Record Changes in All Admin Tables

2011-05-27 Thread Lee
All of my tables have 4 audit fields:

created (timestamp)
created_by (user name)
updated (timestamp)
updated_by (user name)

I'd like to define a subclass of models.Model that sets these fields
on create/update, and then make all my models of that subclass -- but
all the related posts I see imply that the user name is not available
in many contexts.

This seems basic for database apps, but I'm not finding a solution.
Anyone get this to work, and where did you define the subclass?

Thanks for any help or ideas.

-- 
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: Getting "most"

2011-05-27 Thread bax...@gretschpages.com
And that works, with one
exception: .get_object_for_this_type(pk=object['object_id'])

Getting the objects IS a bit inefficient, but since I only need the
top 10, I can live with it.

On May 27, 12:32 pm, Jason Culverhouse  wrote:
> If you were to do something like this:
>
> from django.models import count
> most = Watch.objects.values('content_type', 
> 'object_id').annotate(Count('object_id')).order_by('-object_id__count')
>
> [
>         {'object_id__count': 15, 'object_id': 1, 'content_type': 10},
>         {'object_id__count': 2, 'object_id': 1, 'content_type': 5},
>         ...
> ]
>
> # this isn't efficient, but you get the idea
> # you need to resolve the content types and object id's into models
> from django.contrib.contenttypes.models import ContentType
> for object in most:
>         foo = ContentType.objects.get(id= 
> object['content_type']).get_object_for_this_type(object['object_id'])
>
> You can also seehttps://github.com/coleifer/django-generic-aggregation
>
> This will get you close but I think it only if you want to annotate the count 
> on a single content type at once.
>
> Jason Culverhousehttp://www.mischievous.org

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



Form and ForeignKey Limiting

2011-05-27 Thread Christoffer Viken
Hi,
I am having a bit of a problem with a form.

example (mind the psudo code)
(Model user: included in Django)

Model manager:
    user = ForeignKey(user)

Model task:
    user = ForeignKey(user)
manager = ForeignKey(manager)

What I want to do somehow. Is with a form, being able to create a new
task, and select a manager. (Must be set)
The tricky part is that I ONLY want managers with "user == current
user" to be options.
ModelChoiceField is apparently out of the question; because there is
no way, that i can find, that let me access request.user to narrow the
queryset down.

Am I looking at this problem the wrong way?
I was thinking of adding a field with a non-existing widget (no HTML
rendered) and let the view render the field in HTML; but I can't find
a None-widget.
My total backup everything else fails is to use a ChoiceField with a
Select widget, and write some AJAX code to fill in the data, but that
would require javascript support.

I'll give more details if needed.

Thanks.
--Desktop Browser-
Christoffer Viken / CVi
i=0
str="kI4dJMtXAv0m3cUiPKx8H"
while i<=20:
    if i%3 and not i%4:
        print str[i],
    i=i+1

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



Display Model.id in fieldsets used in Admin Site

2011-05-27 Thread Frisbie
Hello,

Is there any way to display a display a Model's id field using the
fieldsets field in the Admin model? For example:

class CodeJobAdmin(admin.ModelAdmin):
fieldsets = [
#('JobID', {'fields': ['id']}),
('Status', {'fields': ['status', 'owners']}),
# more fields...
]
# more entries...

admin.site.register(CodeJob, CodeJobAdmin)

This works fine, UNLESS I un-comment the line "#('JobID', {'fields':
['id']}),". If I do, I get an error such as:

"ImproperlyConfigured at /admin/general/codejob/37/
'CodeJobAdmin.fieldsets[0][1]['fields']' refers to field 'id' that is
missing from the form."

Anybody know if it's possible to access CodeJob.id (or CodeJob.pk)
through fieldsets?

Thanks,
-Brian Frisbie

--

P.S. I know the Model id can be displayed using list_display, e.g.:

list_display = ('id', getFileName, 'status', 'toolNum', 'date')

but I want the id to be viewable on the Model object webpage.

-- 
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: Django Admin static base.css ignored

2011-05-27 Thread Lee
> How are you telling Django about your overridden CSS? Are you specifying it
> in the ModelAdmin class, or in an overridden template?
>
> I hope you're not expecting it to be picked up automatically, as there's
> nothing in the documentation to imply that is the case.
> --
> DR.

Well, collectstatic copied the base.css to myproject/static_files/
admin/css/base.css, and if I inspect elements on the Admin pages with
Firebug they are styled by 
http://myprojectdomain:8000/static/admin/css/base.css,
so it looks like everything is hooked up.

-- 
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: Django Admin static base.css ignored

2011-05-27 Thread Daniel Roseman
On Friday, 27 May 2011 20:04:03 UTC+1, Lee wrote:
>
> I've customized myproject/static_files/admin/css/base.css but my 
> customizations are ignored. If I make changes to /usr/lib/python2.4/ 
> site-packages/django/contrib/admin/media/css/base.css it works fine. 
> I've double-checked the STATIC settings in settings.py and all looks 
> correct. Any ideas? 
>
> Thanks for any help. 
>
> Lee


How are you telling Django about your overridden CSS? Are you specifying it 
in the ModelAdmin class, or in an overridden template?

I hope you're not expecting it to be picked up automatically, as there's 
nothing in the documentation to imply that is the case.
--
DR.

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



Django Admin static base.css ignored

2011-05-27 Thread Lee
I've customized myproject/static_files/admin/css/base.css but my
customizations are ignored. If I make changes to /usr/lib/python2.4/
site-packages/django/contrib/admin/media/css/base.css it works fine.
I've double-checked the STATIC settings in settings.py and all looks
correct. Any ideas?

Thanks for any help.

Lee

-- 
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: Is there an HTML editor that's Django-aware

2011-05-27 Thread Doug Ballance
Everyone has different requirements, but I'm one of those strange
people who don't care about having a powerful editor.  I don't want
completion, or auto-anything.  Just something that gets out of my way
and lets me work.  If something complex needs to be done on occasion,
that's what the shell and associated command tools are good for. I
also prefer an editor that doesn't suck up a gig of ram like most of
the java based editors/IDEs seem to.  My search for a simple editor
with basic project support ended up with a relatively new
gtksourceview2 based editor called Codeslayer: Starts in around a
second, and uses a whopping 20m of ram:

http://code.google.com/p/codeslayer/

with a django language-spec:
http://code.google.com/p/gedit-django-template-language/

and a decent theme, and additional language-spec for python:
http://mystilleef.blogspot.com/2010/07/new-dark-minimalist-theme-for.html

Which ends up looking like this: http://tinyurl.com/43v8dcf

Gedit with plugins is similar, but a bit heavier - I also had a lot of
trouble with the filebrowser/project manager working over sshfs at
reasonable speed.

Another lightweight alternative is PIDA with emacs or VIM as the
editor base. If you can handle the learning curve, which I don't care
to: http://pida.co.uk/

-- 
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: Getting "most"

2011-05-27 Thread Jason Culverhouse

On May 27, 2011, at 9:58 AM, bax...@gretschpages.com wrote:

> I have a "watch" model that lets users keep an eye on various things
> through a generic relation:
> 
> class Watch(models.Model):
>subscriber = models.ForeignKey(User, verbose_name="Subscriber")
>content_type = models.ForeignKey(ContentType)
>content_object = generic.GenericForeignKey()
>object_id = models.IntegerField('object ID')
>created = models.DateTimeField(auto_now_add=True)
> 
> 
> What I'm trying to do is get the most-watched objects.
> I saw James Bennett's snippet from 2007 (http://djangosnippets.org/
> snippets/108/) which looks like it would work (subbing my Watch model
> for comments), but I'm wondering if there's a better way to do it with
> newer versions of django, possibly through annotate or aggregate?
> 

If you were to do something like this:

from django.models import count
most = Watch.objects.values('content_type', 
'object_id').annotate(Count('object_id')).order_by('-object_id__count')

[
{'object_id__count': 15, 'object_id': 1, 'content_type': 10},
{'object_id__count': 2, 'object_id': 1, 'content_type': 5},
...
]

# this isn't efficient, but you get the idea
# you need to resolve the content types and object id's into models 
from django.contrib.contenttypes.models import ContentType
for object in most:
foo = ContentType.objects.get(id= 
object['content_type']).get_object_for_this_type(object['object_id'])


You can also see
https://github.com/coleifer/django-generic-aggregation

This will get you close but I think it only if you want to annotate the count 
on a single content type at once.

Jason Culverhouse
http://www.mischievous.org

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



Getting "most"

2011-05-27 Thread bax...@gretschpages.com
I have a "watch" model that lets users keep an eye on various things
through a generic relation:

class Watch(models.Model):
subscriber = models.ForeignKey(User, verbose_name="Subscriber")
content_type = models.ForeignKey(ContentType)
content_object = generic.GenericForeignKey()
object_id = models.IntegerField('object ID')
created = models.DateTimeField(auto_now_add=True)


What I'm trying to do is get the most-watched objects.
I saw James Bennett's snippet from 2007 (http://djangosnippets.org/
snippets/108/) which looks like it would work (subbing my Watch model
for comments), but I'm wondering if there's a better way to do it with
newer versions of django, possibly through annotate or aggregate?

-- 
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: caching ajax json (post)

2011-05-27 Thread Malcolm Box
On 27 May 2011 08:12, Олег Корсак  wrote:

> Hello. Is there a way to cache ajax json responce after post request
> like after get?
> Thanks.
>
> Where do you want to cache it?
Why do you want to cache a POST request? POST should be used to alter the
state of the application - so it's probable that whatever was cached before
is no longer valid.

If you really, really want to do this using Django, it has nothing to do
with AJAX or JSON. Just alter your view function to cache the POST response
and replay it to the next POST. You get to choose what comes back from your
views.

Malcolm



-- 
Malcolm Box
malcolm@gmail.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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



invalid label

2011-05-27 Thread Bobby Roberts
ok got a strange situation here.  I'm using Satchmo for a shopping
cart and have an independent module i wrote which is called from the
main nav.  This module works fine on every page of the site except for
the product detail page in Satchmo.  When i view the page in satchmo i
get this error:


Django Version: 1.3 pre-alpha SVN-14462
Exception Type: TemplateSyntaxError
Exception Value:

Caught RuntimeError while rendering: invalid label: cigar-wizard

where cigar-wizard is the name of my module... it has nothing to do
with satchmo.  any idea what invalid label means?  I don't see
anything like this in the docs anywhere

-- 
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: Form Validation - Redisplay With Error

2011-05-27 Thread Robin
Thanks, Derek!  Wikipedia makes good sense.

On May 27, 1:14 am, Derek  wrote:
> On May 26, 1:07 am, Robin  wrote:> I'm very 
> comfortable with SQL and more traditional programming.  Would
> > you recommend some specific HTTP primer, or anything  else for those
> > making the transition to web dev?
>
> Assuming good faith in the wisdom of the crowd... 
> :http://en.wikipedia.org/wiki/Http
> An older intro (ignore 
> CGI!):http://www.orion.it/~alf/whitepapers/HTTPPrimer.html
> Formal specs:http://www.w3.org/standards/techs/http#w3c_all

-- 
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: Django Model Designer - UML

2011-05-27 Thread Lee
If you can generate the DDL with your tools, build the new database
and point inspectdb at it to generate Django models:

https://docs.djangoproject.com/en/dev/howto/legacy-databases/?from=olddocs?from=olddocs

On May 27, 8:06 am, Mateusz Harasymczuk 
wrote:
> I am looking for a GUI tool for modeling Django model classes.
>
> I have a pretty large app and I need to refactor it.
> I used django-extensions and *graph_models* to dump the schema to the
> GraphViz dot file.
> And I am stuck here :}
>
> I would like to import either GraphViz dot file, or models source files,
> make changes and generate output Python+Django code.
>
> Has anyone did something like that?

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



@login_required & Redirect...best practice?

2011-05-27 Thread Robin
When I have a view that's @login_required -- and the user isn't logged
in -- what's the best way to deal with the URL they wanted in the
first place?  Assuming they log in properly and I want to then
redirect them on to where they intended to go in the first
place...what's the best practice?

I'm new to web development and I would like to do things the right way
so I can eventually build apps that can support an online store, etc.

I would appreciate your input and ideas I can research.

-- 
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: sitemaps not quite as easy to setup as suggested?

2011-05-27 Thread i...@webbricks.co.uk
found the following snippet of code, managed to get it doing what i
want with it.

http://stackoverflow.com/questions/4836188/django-sitemaps-and-normal-views

Matt

On May 27, 4:45 pm, Addy Yeow  wrote:
> I keep sitemap for those objects in 1 sitemap file, and manually create
> another sitemap file for all my static pages.
> Then, create a sitemap index to point to the two.
>
> Would love to hear from others though.
>
> On Fri, May 27, 2011 at 11:22 PM, i...@webbricks.co.uk 
>
>
>
>
>
>
>
>
> > wrote:
> > ok, read the docs properly and understood it a bit more. im stuck with
> > one thing though. i get how simple it is to tell the sitemap about all
> > the objects that have been created but what about the static pages,
> > where you've not used flatpages. for instance a contact form you've
> > created, this should be in the sitemap, but isnt a flatpage.
>
> > how do i go about adding them to the dict in the urls file?
>
> > --
> > 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.
>
> --http://www.dazzlepod.com.http://twitter.com/dazzlepod
> We write elegant and minimal apps that works. We develop web apps with
> Django framework.

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



Django dynamic form simple Example

2011-05-27 Thread Afshin Moshrefi
I have a simple requirement for creating a dynamic form in Django -
I've seen many examples but they seem to be incomplete, or require
more extensive knowledge of Python and Django than I have!  None show
how the dynamic portion of the example should be called:

This is the form class with Q1 and Q2 - I place a button on the form
to add another
field called Q3 - and then Q4 if pressed again:  I think I got the
__init__ function semi correct:

class testform(forms.Form)
Q1 = forms.CharField()
Q2 = forms.CharField()

def __init__(self, *args, **kwargs):
super(testform,self).__init__(*args,**kwargs)
self.fields['Q%s'%i] = forms.CharField(label='Q%i' % i)


I want to place a button on the form to add another
field called Q3 and then Q4 if pressed again.

- How do I call the __init__function from the view to add these
fields?
- If I use Javascript to add the field dynamically, how do I call
__init__ so that I can correctly validate with Django when I POST the
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: sitemaps not quite as easy to setup as suggested?

2011-05-27 Thread Addy Yeow
I keep sitemap for those objects in 1 sitemap file, and manually create
another sitemap file for all my static pages.
Then, create a sitemap index to point to the two.

Would love to hear from others though.

On Fri, May 27, 2011 at 11:22 PM, i...@webbricks.co.uk  wrote:

> ok, read the docs properly and understood it a bit more. im stuck with
> one thing though. i get how simple it is to tell the sitemap about all
> the objects that have been created but what about the static pages,
> where you've not used flatpages. for instance a contact form you've
> created, this should be in the sitemap, but isnt a flatpage.
>
> how do i go about adding them to the dict in the urls file?
>
> --
> 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.
>
>


-- 
http://www.dazzlepod.com . http://twitter.com/dazzlepod
We write elegant and minimal apps that works. We develop web apps with
Django framework.

-- 
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: sitemaps not quite as easy to setup as suggested?

2011-05-27 Thread i...@webbricks.co.uk
ok, read the docs properly and understood it a bit more. im stuck with
one thing though. i get how simple it is to tell the sitemap about all
the objects that have been created but what about the static pages,
where you've not used flatpages. for instance a contact form you've
created, this should be in the sitemap, but isnt a flatpage.

how do i go about adding them to the dict in the urls file?

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



Django Model Designer - UML

2011-05-27 Thread Mateusz Harasymczuk
I am looking for a GUI tool for modeling Django model classes.

I have a pretty large app and I need to refactor it.
I used django-extensions and *graph_models* to dump the schema to the 
GraphViz dot file.
And I am stuck here :}

I would like to import either GraphViz dot file, or models source files, 
make changes and generate output Python+Django code.

Has anyone did something like that?

-- 
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: Django development with iPad as target platform?

2011-05-27 Thread rafael.nu...@gmail.com
In development now, and using Sencha Touch(ExtJS)
http://www.sencha.com/products/touch/.

--Rafael

On Fri, May 27, 2011 at 11:21 AM, Thomas Weholt wrote:

> I just got my hands on an iPad and was wondering if anybody has done
> any django development where the iPad was the target
> platform/browser/client?
>
> Thanks in advance and expect some django-app aimed at ipad in the near
> future ;-).
>
> --
> Mvh/Best regards,
> Thomas Weholt
> http://www.weholt.org
>
> --
> 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.
>
>

-- 
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: Django development with iPad as target platform?

2011-05-27 Thread Shawn Milochik

On 05/27/2011 10:21 AM, Thomas Weholt wrote:

I just got my hands on an iPad and was wondering if anybody has done
any django development where the iPad was the target
platform/browser/client?

Thanks in advance and expect some django-app aimed at ipad in the near
future ;-).

As someone who had an iPad for over a year, I'd say there there's really 
nothing to "target." You have a very usable browser and screen size, and 
I didn't have problems with any sites that I can think of.


The only thing I wish sites would do is to STOP redirecting my phones 
and tablets to their "mobile version." I hate that.



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



Django development with iPad as target platform?

2011-05-27 Thread Thomas Weholt
I just got my hands on an iPad and was wondering if anybody has done
any django development where the iPad was the target
platform/browser/client?

Thanks in advance and expect some django-app aimed at ipad in the near
future ;-).

-- 
Mvh/Best regards,
Thomas Weholt
http://www.weholt.org

-- 
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: 200 OK message

2011-05-27 Thread Brendan Smith
bump?

On Thu, May 26, 2011 at 11:11 AM, Brendan Smith <
bren...@nationalpriorities.org> wrote:

> hey all,
>
> I pushed some changes to my code last night and this morning upon trying to
> add an object (based on a model I added last night) this morning I am
> getting the following response:
>
> OK
>
> None of the range-specifier values in the Range request-header field
> overlap the current extent of the selected resource.
> --
> Apache/2.2.12 (Ubuntu) Server at nationalpriorities.org Port 80
>
> If I refresh a few times I can get the admin change form to appear, but
> almost every time I go directly from "Add Table+" (table is my model) I get
> this message.anyone have any idea what this is all about?
>
> thanks,Brendan
>
> --
> Brendan Smith, IT Specialist
> National Priorities Project
> http://www.nationalpriorities.org
> http://www.costofwar.com
> http://www.facebook.com/nationalpriorities
> 413 584 9556
>



-- 
Brendan Smith, IT Specialist
National Priorities Project
http://www.nationalpriorities.org
http://www.costofwar.com
http://www.facebook.com/nationalpriorities
413 584 9556

-- 
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: nested template tags

2011-05-27 Thread bruno desthuilliers
On May 26, 9:21 am, Andreas Rammhold 
wrote:
> Heya,
> I'm not 100% sure if this solves the problem

I'm 101% sure it doesn't.

> for you (or if it's even
> intended to do what you want) but:
>
> {% with old_i=i %}
>     {{ i 
> }}
> {% endwith %}

Except for the useless aliasing of 'i', how is this different from the
OP's snippet exactly ?

> Haven't tried that yet but could be worth a shot.

http://en.wikipedia.org/wiki/Programming_by_permutation

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



django-cms and photologue

2011-05-27 Thread Dave Sayer
Hi All,

I have a question relating to integrating django-photologue with
django-cms. I have added the cmsplugin-photologue app and am now
attempting to add the relevant tags to my templates. The trouble is,
is that I can't seem to find the correct tags for getting the relevant
data from photologue. Having spent some time googling and looking
through the docs, I have come no closer to an answer. I just want to
display a photo that's been attached to a page. I thought it would be
simple...perhaps it's a wood for the trees moment but i'd really
appreciate some help.

Cheers,

Dave

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



Django admin and jQuery select filtering

2011-05-27 Thread Ryan
Hi,

First of all I will start by saying that I am fairly new to django, jQuery 
and javascript, but have been using python for a number of years now.  In 
order to get to know django, I thought I would try to develop a ladder 
application to display player rankings for my local squash club.  As part of 
this I wanted to add some ajax to some of my forms in the django admin in 
order to dynamically filter some of the options in a select box depending on 
the users selection in the previous box.  For example, when adding a new 
player to a ladder, it makes little sense to allow the user to select a 
player who is already a member of that ladder.  In order to do this, I have 
created a new model form as shown here: http://pastebin.com/y2uZxmnF.  I 
then wrote the following javascript (selectfilter.js): 
http://pastebin.com/vyHXzMH2.  Finally I wrote a view to select the required 
objects: http://pastebin.com/D2JVNHxS.

This works great, however, I need to use the same kind of functionality on 
other forms, but there is a lot hardcoded in to the javascript file and view 
so would require a new javascript file for each new form.  So I was 
wondering if there was a good way to make this more dynamic so the same code 
could be used for most (if not all) forms?

Any help would be greatly appreciated.

Many thanks,

Ryan

-- 
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: Looking for Class Base Views intro (not Generic Class Base Views!)

2011-05-27 Thread Brian Bouterse
One reason its hard to pull the concept of Class Based views and Generic
views apart is because they actually go together.  Consider the following:

1.  Class based views typically use the
as_view()class
method as its entry point, which is typically provided through
inheriting from
django.views.generic.base.View
2.  Not inheriting from django.views.generic.base.View would require you to
implement the Class Based Views behavior and interfaces just like Django
already has, which is silly when you can just subclass the generic 'View'
function.
3.  So class based views tend to always inherit from some generic django
view ... django.views.generic.base.View at the very least.

Hope this is helpful,
Brian

On Thu, May 26, 2011 at 7:39 PM, Mateusz Harasymczuk  wrote:

> Anyone?
> Class Based Views?
>
>  --
> 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.
>



-- 
Brian Bouterse
ITng Services

-- 
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: nested template tags

2011-05-27 Thread ozgur yilmaz
thanks for your help...

template tag:
@register.filter(name='get_page')
def get_page(var, name):
return u"%s=%d" % (name,var)

template:
{% with i|get_page:'page' as xxx %}
i
{% endwith %}

yes, i was planning to use snippet at
http://djangosnippets.org/snippets/553/ for get parameters.



2011/5/26 Andreas Rammhold :
> Heya,
> I'm not 100% sure if this solves the problem for you (or if it's even
> intended to do what you want) but:
>
> {% with old_i=i %}
>    {{ i }}
> {% endwith %}
>
> Haven't tried that yet but could be worth a shot.
>
> https://docs.djangoproject.com/en/1.3/ref/templates/builtins/#with
>
>
> On Thu, May 26, 2011 at 9:08 AM, ozgur yilmaz  wrote:
>> Hi,
>>
>> I want to use an expression like this:
>>
>> {{ i }}
>>
>> The first {{ i }} is in another tag. is there any way to manage this problem?
>>
>> 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 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://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-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.
>
>

-- 
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: Overridden Admin Template Not Recognized

2011-05-27 Thread Brian Bouterse
You'll need make sure that "django.template.loaders.filesystem.Loader" is
enabled in your TEMPLATE LOADERS to use the app in the way you want.  Also,
you'll need to place your app BEFORE the 'django.contrib.admin' application
in the INSTALLED_APPS list.

Hope this helps,
Brian

On Thu, May 26, 2011 at 6:17 PM, Lee  wrote:

> I'm trying to override the TabularInline template following the
> instructions in
> https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates
> .
> I copied the tabular.html file to myproject/templates/admin/myapp and
> made changes to it, but they have no effect. I double-checked
> TEMPLATE_DIRS in settings.py and it includes the myproject/templates
> directory.
>
> Thanks for any help or ideas.
>
> Lee
>
> --
> 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.
>
>


-- 
Brian Bouterse
ITng Services

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



sitemaps not quite as easy to setup as suggested?

2011-05-27 Thread i...@webbricks.co.uk
hi all, struggling to get sitemaps setup. followed docs, including
working out there was an import missing in the docco.

this is the copy n paste error

Environment:


Request Method: GET
Request URL: http://coatesconstruction.co.uk/sitemap.xml

Django Version: 1.3
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sitemaps',
 'django.contrib.admin',
 'frontpage',
 'contact_form',
 'projects',
 'testimonials',
 'south']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/home/shofty/virtualenvs/coates/lib/python2.5/site-packages/
django/core/handlers/base.py" in get_response
  111. response = callback(request,
*callback_args, **callback_kwargs)
File "/home/shofty/virtualenvs/coates/lib/python2.5/site-packages/
django/contrib/sitemaps/views.py" in sitemap
  33. maps = sitemaps.values()

Exception Type: AttributeError at /sitemap.xml
Exception Value: 'module' object has no attribute 'values'

should i be populating sitemaps in the urls file?

-- 
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: where is 'request' as in from x import y

2011-05-27 Thread bruno desthuilliers
On May 27, 10:58 am, MikeKJ  wrote:
> Interesting, I thought I was doing that in my save method but obviously I
> cant be.

Of course it can't. The request only exists when there's an actual
HTTP request sent to your HTTP server. Your model code is (hopefully)
totally independant and unaware of the mere existence of something
like an HTTP request. How else would you work with your data outside
HTTP requests ? (I mean management scripts / commands, cron jobs, GUI
or CLI client, whatever).

-- 
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 save method - inlineformset_factory

2011-05-27 Thread rayfidelity
Hi,

This is my models.py

class Invoices(models.Model):
...
sum_w_vat = models.DecimalField(max_digits=7, decimal_places=2,
default=0)
sum_wo_vat = models.DecimalField(max_digits=7, decimal_places=2,
default=0)
sum_discount = models.DecimalField(max_digits=7, decimal_places=2,
default=0)
sum_vat = models.DecimalField(max_digits=7, decimal_places=2,
default=0)
sum_paid = models.DecimalField(max_digits=7, decimal_places=2,
default=0)
...

class InvoiceItems(models.Model):
invoice = models.ForeignKey(Invoices)
quantity = models.DecimalField(max_digits=9, decimal_places=2)
unit = models.ForeignKey(StocklistUnits, verbose_name='Merska
enota')
price = models.DecimalField(max_digits=9, decimal_places=2)
vat = models.DecimalField(max_digits=4, decimal_places=3)
discount = models.DecimalField(max_digits=3, decimal_places=1)
def save(self, **kwargs):
self.invoice.sum_w_vat += (self.price * self.quantity *
self.vat) * self.discount
self.invoice.sum_wo_vat += (self.price * self.quantity) *
self.discount
self.invoice.sum_discount += (self.price * self.quantity) *
( self.discount / 100 )
self.invoice.sum_vat += ((self.price * self.quantity *
self.vat) * self.discount) - ((self.price * self.quantity) *
self.discount)
super(InvoicesItems, self).save(**kwargs)

I don't know how to save the calculated data in the InvoiceItems
redefined save function... this obviously doesn't work, because
Invoices get saved first...

views.py

def edit(request, id = None):
InvoiceFormSet = inlineformset_factory(Invoices, InvoicesItems)

if id == None:
initial_data = ''
data = Invoices()
else:
data = get_object_or_404(Invoices, pk=id)
initial_data = ''

if request.method == 'POST':
created_invoice = InvoicesForm(request.POST, instance=data)

form = InvoiceFormSet(request.POST, instance=data)

if not form.is_valid() and not created_invoice.is_valid():
//json err msg
else:
created_invoice.save()
form.save()


json = simplejson.dumps(response, ensure_ascii=False)
return HttpResponse(json, mimetype="application/json")
else:
form = InvoicesForm(instance=data, initial=initial_data)
form_items = InvoiceFormSet(instance=data)
c = {'form':form, 'form_items':form_items}
c.update(csrf(request))
return render_to_response('crud_invoice_edit.html', c)

How can I iterate through the InvoiceItems and calculate the field
which then need to be inserted into Invoices. I'm new to django...

Thank you!

-- 
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 User class

2011-05-27 Thread venky
In one of my applications while defining models I have made django
provided "User" class as super class for my custom user class (myuser)
as shown below. In the database, I see that there is a pointer record
pointing to User table (in my custom "myuser" table). The problem
here, when I reset my application database, it does not delete entries
in parent class ie. User (from django.auth.contrib). It can be
resolved by resetting database for auth. Would it be possible to
delete all relevant entries in auth while resetting my application
database?

Also, is there any better way to define my custom user class?

class myuser(User):




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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: OperationalError: no connection to the server using Django and gunicorn

2011-05-27 Thread Adrián Ribao
I'm doing it manually because I'm just testing:

./manage.py run_gunicorn -c gunicorn.conf.py

where gunicorn.conf.py

# -*- coding: utf-8 -*-
import multiprocessing

bind = "127.0.0.1:8000"
workers = multiprocessing.cpu_count() * 2 + 1
worker_class = 'gevent'


On 27 mayo, 02:23, Shawn Milochik  wrote:
> What's the command you're using to run it?
>
> Are you in screen? Are you using supervisor or anything like that?

-- 
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: Is there an HTML editor that's Django-aware

2011-05-27 Thread Tom Evans
On Thu, May 26, 2011 at 9:05 PM, AJ  wrote:
> I'd like to know why people really like Vim if it is "a piece of shit" ?
> Just want to know because I try to learn it everytime and I hear great
> things about it.
>
>

We're all coprophiliacs. But seriously..

One of the Pragmatic Programmer tips (buy the book if you haven't)
goes as follows:

Use a Single Editor Well
The editor should be an extension of your hand; make sure your editor
is configurable, extensible, and programmable.

vim is one of the ultimate power user editors. It basically does
everything, and it does it in a simple to understand manner. What's
more, it is fast and efficient to use; once mastered, you will be more
productive as a vim user than with most other editors.

The downside is that it is quite complex to learn. If you spend 5-6
hrs a day in your editor, then you should expect to become competent
in vim in about a month, and skilled in about a year.

vim has lots of features that require you to remember how to use them.
For instance, some people like to have tabs for their files. In vim,
you can do this easily, you ':tab new foo.html'.
You can then click on the tab to switch to that buffer. You can also,
type 'gt' to go to the next tab, or 'gT' to go to the previous tab.
Some people find things like that difficult to remember - although it
is actually easy, 'g' in vim commands means 'go', so 'gt' == 'go tab',
just like 'gg' means go to line 1, '10gg' means 'go to line 10' and
'G' means go to the last line in the file - and give up using vim.

In the office I work in, we have around 20 developers. 2 use TextPad,
the rest use vim. Most never used vim before starting here, the top
tip I can give is to print out a cheat sheet and pin it to your
monitor.

Cheers

Tom

-- 
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: where is 'request' as in from x import y

2011-05-27 Thread MikeKJ

Interesting, I thought I was doing that in my save method but obviously I
cant be.

example.
Model 1:
auth_user_id
row_id_of model_being_saved
timestamp

Model 2:
something

def save(self):
auth_user_id = request.user.id
row_id_of_model_being_saved = something
Model 1.save()
super( Model 2, self).save()

I should not that this is retro stuff as in 0.97 pre code (old site), now
that throws the request error

Cheers

Now, your last sentence reveals what you actually want to do, and of course 
Django has a way to achieve that: override the `save_model` method in the 
ModelAdmin class. That method does get the request passed in.
--
DR.

-- 

-- 
View this message in context: 
http://old.nabble.com/where-is-%27request%27-as-in-from-x-import-y-tp31706142p31714838.html
Sent from the django-users mailing list archive at Nabble.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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: admin ordering for NULL fields

2011-05-27 Thread Kirill Spitsin
On Fri, May 27, 2011 at 12:35:26AM -0700, Dennis Schmidt wrote:
> In the admin panel I set a (descending) ordering on a model's date
> field. That's fine of course. Now, the "problem" is, that this field
> may be NULL in some cases and I want these items to appear at the
> beginning of the list. They appear at the very end. If I set the
> ordering to ASCENDING, then they do appear at the beginning but the
> rest of the order is, of course, not how I want it.
> 
> So I couldn't find something in the documentation how I could achieve
> what I want. Any tips, hints?

http://www.mail-archive.com/django-users@googlegroups.com/msg64668.html

-- 
Kirill Spitsin

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



admin ordering for NULL fields

2011-05-27 Thread Dennis Schmidt
In the admin panel I set a (descending) ordering on a model's date
field. That's fine of course. Now, the "problem" is, that this field
may be NULL in some cases and I want these items to appear at the
beginning of the list. They appear at the very end. If I set the
ordering to ASCENDING, then they do appear at the beginning but the
rest of the order is, of course, not how I want it.

So I couldn't find something in the documentation how I could achieve
what I want. Any tips, hints?

Cheers, Dennis

-- 
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: Form Validation - Redisplay With Error

2011-05-27 Thread Derek
On May 26, 1:07 am, Robin  wrote:
> I'm very comfortable with SQL and more traditional programming.  Would
> you recommend some specific HTTP primer, or anything  else for those
> making the transition to web dev?
>
Assuming good faith in the wisdom of the crowd... :
http://en.wikipedia.org/wiki/Http
An older intro (ignore CGI!):
http://www.orion.it/~alf/whitepapers/HTTPPrimer.html
Formal specs:
http://www.w3.org/standards/techs/http#w3c_all

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



caching ajax json (post)

2011-05-27 Thread Олег Корсак
Hello. Is there a way to cache ajax json responce after post request
like after get?
Thanks.



signature.asc
Description: OpenPGP digital signature


Re: json serialization question

2011-05-27 Thread Ian Clelland
On Tue, May 24, 2011 at 8:36 AM, Sells, Fred
wrote:

> My code looks like this
>
> records = models.Residents.objects.extra( where=[], params=[...])
> data = serializers.serialize('json', records, ensure_ascii=False,
> fields=('fname','lname', 'pt'))
> return HttpResponse(data)
>
> After experimenting the "ensure_ascii=False" seems to get rid of the
> Unicode prefix which is not used in my work.
>
> which returns
> [
> {"pk": "7", "model": "app.residents", "fields": {"lname": "Mouse ",
> "pt": "0", "fname": "Minnie "}},
> ...]
>
> I was surprised to see the subnode "fields" in the output.  Perhaps I'm
> just old school having does basic cgi with json and pretty much forced
> the format.
>
> 1. However is the above the "best practice" or is there an option to
> strip the meta data.
>

I don't think that anyone would condone this as a 'best practice' -- the
Django serializers are meant to dump django objects, say into session data,
or into database fixtures, and they are really designed to be read by the
deserializers when the object needs to be reconstructed.

If you are passing data from Django to a browser's JavaScript thread using
JSON, then you probably want to either

1. Use an API framework, such as Piston (google: django-piston) or TastyPie
(google: django-tastypie) to handle serialization of outgoing data. These
are very useful if you expect to be receiving data from the browser in the
same format for creating or updating objects, but they can be a lot of
overhead for small applications, so you may want to

2. Write your own serialization. It's quite simple, and Django does an
excellent job of packaging the simplejson library (deferring to the system
installed version, if it's available, and newer than Django's). All you need
to do is something like this:

from django.utils import simplejson as json
...
records = models.Residents.objects.extra( where=[], params=[...])
data = json.dumps(records.values('fname','lname','pt'))
return HttpResponse(data, mimetype='application/json')

records.values(...) should return just the dictionary that you want to use.
json.dumps(...) will convert that into a JSON string, which you can then
return as an HttpResponse.


-- 
Regards,
Ian Clelland


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