Re: Relation not found error while dealing with foreign keys and forms

2011-11-03 Thread Tabitha Samuel
K, so that worked...

This is what I got:
In [5]: i = Staff.objects.using('gold').get(username='tsamuel')

In [6]: i.nics_group.n_group_name
Out[6]: u'Systems and Operations'

Looks like the foreign key is working fine from the db's perspective.
This is how I'm getting the form:
form = StaffForm(instance = Staff.objects.using('gold').get(username
=current_staff))
where current_staff = 'tsamuel'
and then if I do a print form, I get a relation n_nics_groups does not
exist error.

Once again, thank you so much for your help, I really appreciate it!

Tabitha

On Nov 3, 1:26 pm, Furbee  wrote:
> I may have lead you astray. I set up the same models on my end and get the
> same query; it didn't show the join of the foreign key in the QuerySet of
> Staff, but when I did a get() on username='tsamuel' I got a Staff object.
> Then I was able to get the group they belonged to. This was successful for
> me:
>
> Here's my data:
>
> table: n_nics_groups
> n_group_number; n_group_name
> 1; "TestGroup1"
> 2; "TestGroup2"
> 3; "TestGroup3"
>
> table: n_test_staff
> "tfigura";"";"";"";"";"";"";"";"";2;"";"''";"";"";"";1;1;1;;"''";"''";"''";"''";"";FALSE;TRUE
> "tsamuel";"";"";"";"";"";"";"";"";1;"";"''";"";"";"";1;1;1;;"''";"''";"''";"''";"''";FALSE;TRUE
>
> 'tfigura' is in group with n_group_number 2, tsamuel is in group with
> n_group_number 1.
>
> python manage.py shell:
>
> >>> from project.models import NICSGroupType, Staff
> >>> i = Staff.objects.get(username='tsamuel')
> >>> i.nics_group.n_group_name
> >>> u'TestGroup1'
>
> Is this operational for your instance? If not, I would double check that
> the n_nics_groups table definitely exists in the datasource you defined as
> 'gold.' This should be defined in the DATABASES section of settings.py. It
> looks like it is the database 'public' from your example, but double check
> that the 'gold' DATABASE points there.
>
> Otherwise, I wonder if it is somewhere where you are defining the form
> object. First, let's verify that the foreign key reference is being honored
> on your system, by running the above test, to verify that the group is
> printed, when you get() a specific record and print the
> nics_group.n_group_name.
>
> Thanks,
>
> Furbee
>
> On Wed, Nov 2, 2011 at 5:09 PM, Tabitha Samuel 
> wrote:> Thank you so much for your reply! So I got 
> a "Staff object has no
> > attribute 'query'" error when I did it with the get. I got the sql
> > when I tried it with the filter instead (instance =
> > Staff.objects.using('gold').filter(username='tsamuel') >>
> > str(instance.query))this is what I'm getting:
>
> > 'SELECT "n_test_staff"."username", "n_test_staff"."home_phone",
> > "n_test_staff"."cell_phone", "n_test_staff"."home_address",
> > "n_test_staff"."home_city", "n_test_staff"."home_state",
> > "n_test_staff"."home_zip", "n_test_staff"."emergency_name",
> > "n_test_staff"."emergency_phone", "n_test_staff"."nics_group",
> > "n_test_staff"."room_number", "n_test_staff"."title",
> > "n_test_staff"."supervisor", "n_test_staff"."url",
> > "n_test_staff"."im", "n_test_staff"."last_modification_time",
> > "n_test_staff"."start_date", "n_test_staff"."creation_time",
> > "n_test_staff"."termination_date", "n_test_staff"."bio",
> > "n_test_staff"."photopath", "n_test_staff"."office_phone",
> > "n_test_staff"."email", "n_test_staff"."preferred_name",
> > "n_test_staff"."deleted", "n_test_staff"."viewable" FROM
> > "n_test_staff" WHERE "n_test_staff"."username" = tsamuel '
>
> > Looks like from the query, is not looking into the n_nics_groups
> > table. Question is why?
>
> > Tabitha
>
> > On Nov 2, 6:00 pm, Furbee  wrote:
> > > Can you try this and tell us what you see:
>
> > > Run a shell using python manage.py shell
>
> > > >>> instance = Staff.objects.using('gold').get(username='tsamuel')
> > > >>> str(instance.query)
>
> > > This will tell us whether or not the database, reference, and such are
> > > correctly translating into a query. The error means Django is sending an
> > > erroneous query to your database layer.
>
> > > Furbeenator
>
> > > On Wed, Nov 2, 2011 at 1:54 PM, Tabitha Samuel  > >wrote:
>
> > > > Hi,
>
> > > > In brief here is my problem. I have two simple tables, one has a one
> > > > to many relation with the other. The problem I run into is that when I
> > > > try to create a form instance of the child, and try to print it or
> > > > render it in a template, I run into a "relation not found" error for
> > > > the parent. Simply querying the parent works without a problem.
>
> > > > This is what my models.py looks like:
> > > > from django.db import models
>
> > > > class NICSGroupType(models.Model):
> > > >     n_group_number = models.IntegerField(primary_key = True)
> > > >    n_group_name = models.CharField(max_length = 512)
> > > >    class Meta:
> > > >        db_table = "n_nics_groups"
>
> > > > class Staff(models.Model):
> > > >    username           

Re: django and profile pictures creation

2011-11-03 Thread Kurtis Mullins
One option is to check out userena.

If you don't want to use a third party application, then I would go about
creating a UserProfile that has a one-to-one relationship with each User.
And in that UserProfile Model, create an ImageField for the avatar. Here's
some links to help get you started.

http://django-userena.org/
https://docs.djangoproject.com/en/1.3/topics/auth/#storing-additional-information-about-users
https://docs.djangoproject.com/en/1.3/ref/models/fields/#imagefield

Good luck!

On Thu, Nov 3, 2011 at 9:03 AM, yan  wrote:

> Hello, I am developing a website which will have some social features
> like people profiles, but I am having a problem on how to create a
> space where a person will put his/her profile picture, I am using
> django framework and MySQL, can anyone help me please?
>
> --
> 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.



How can I limit a 'list_filter' to a certain subset of objects?

2011-11-03 Thread Rodrigo Cea
Explanation:

I have 3 models: Client, Project and Task. Each Client has 1 or more 
Projects. Each Project has 1 or more Tasks.
 
A Client can only see the Projects assigned to him and the Tasks assigned 
to one of his Projects. This is already working, overriding "queryset" in 
the ModelAdmin instance.

However, in the changelist for Tasks, there is a list_filter on Projects, 
so a Client can view the Tasks that are assigned to a certain Project. 

THE PROBLEM: this 'Project' filter shows all Projects, whether they're 
assigned to the Client or not. I need it to only show the Projects assigned 
to the Client.

Thanks, 

Rodrigo



-- 
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/-/xO-ARZBOXp4J.
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: Which is the best way of query a database view(no from Django model)

2011-11-03 Thread Andre Lopes
Hi Daniel, thanks for the reply.

I have tested to "inspectdb" but I think the schema is to complex, for
example... for the table "tdir_files_context" (djangoinspectdb.JPG
"image in attachment") I got this model:

[code]
class TdirFilesContext(models.Model):
id_category = models.ForeignKey(TdirCategories, db_column='id_category')
id_file_context = models.CharField(max_length=20)
n_file_context = models.CharField(max_length=150)
coment = models.CharField(max_length=2000)
id_user_db_ins = models.CharField(max_length=45)
id_user_db_upd = models.CharField(max_length=45)
id_user_sys_ins = models.CharField(max_length=45)
id_user_sys_upd = models.CharField(max_length=45)
date_ins = models.DateTimeField()
date_last_upd = models.DateTimeField()
class Meta:
db_table = u'tdir_files_context'
[/code]

This database table have Two primary keys and One foreign key. The
Django Model handle this kind of database tables?


Best Regards,




>> I'm a new to Django...
>>
>> I have a database schema that stores me information that I want to
>> show in a Django website. This database schema have nothing to do with
>> a Django App...
>>
>> Which is the best way of doing this in Django? I have read the
>> documentation and seems to me that I will need to use "custom SQL
>>
>> directly"(https://docs.djangoproject.com/en/1.3/topics/db/sql/#executing-custom-sql-directly),
>> right?
>>
>> If this is correct, where should I put the SQL queries, in "views.py"?
>>
>> Best Regards,
>
> Is there any reason why you can't create models from your existing schema?
> See https://docs.djangoproject.com/en/1.3/howto/legacy-databases/
> --
> DR.
>
> --
> 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/-/khJaBBbvxfIJ.
> 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: Which is the best way of query a database view(no from Django model)

2011-11-03 Thread Daniel Roseman
On Thursday, 3 November 2011 20:04:30 UTC, Andre Lopes wrote:
>
> Hi,
>
> I'm a new to Django...
>
> I have a database schema that stores me information that I want to
> show in a Django website. This database schema have nothing to do with
> a Django App...
>
> Which is the best way of doing this in Django? I have read the
> documentation and seems to me that I will need to use "custom SQL
> directly"(
> https://docs.djangoproject.com/en/1.3/topics/db/sql/#executing-custom-sql-directly
> ),
> right?
>
> If this is correct, where should I put the SQL queries, in "views.py"?
>
>
> Best Regards,
>

Is there any reason why you can't create models from your existing schema? 
See https://docs.djangoproject.com/en/1.3/howto/legacy-databases/
--
DR.

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



Which is the best way of query a database view(no from Django model)

2011-11-03 Thread Andre Lopes
Hi,

I'm a new to Django...

I have a database schema that stores me information that I want to
show in a Django website. This database schema have nothing to do with
a Django App...

Which is the best way of doing this in Django? I have read the
documentation and seems to me that I will need to use "custom SQL
directly"(https://docs.djangoproject.com/en/1.3/topics/db/sql/#executing-custom-sql-directly),
right?

If this is correct, where should I put the SQL queries, in "views.py"?


Best Regards,

-- 
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 at model class level

2011-11-03 Thread Tom Evans
On Thu, Nov 3, 2011 at 2:22 PM, Thomas Guettler  wrote:
> Hi,
>
> I try to reduce the number of db-queries in my app.
>
> There is a model which changes almost never. It is like a "type of ticket"
> in a trouble ticket system.
>
> On one page there are seven SQL-Queries (SELECT  FROM ticket_type where 
> id=123) which of course always return
> the same result.
>
> I want to cache the objects:
>
> t1=TicketType.objects.get(id=123)
> t2=TicketType.objects.get(id=123)
>
> t1 and t2 should be the identical python object, not just objects containing 
> the same data.
>
> Has someone done this before?
>
> Here is my first version:
>
> class ThreadLocalQueryset(models.query.QuerySet):
>    _threadlocal=threading.local()
>    _threadlocal.cache=dict() # The cache is at class-level. It survives a 
> request.
>    def get(self, **kwargs):
>        kwargs_tuple=tuple(kwargs.items())
>        obj=self._threadlocal.cache.get(kwargs_tuple)
>        if obj is not None:
>            return obj
>        obj=models.query.QuerySet.get(self, **kwargs)
>        self._threadlocal.cache[kwargs_tuple]=obj
>        return obj
>
> class ThreadLocalManager(models.Manager):
>    use_for_related_fields = True
>    def get_query_set(self):
>        return ThreadLocalQueryset(self.model, using=self._db)
>
> class TicketType(models.Model):
>    objects=ThreadLocalManager()
>
> If there would be many TicketTypes, the interpreter would use more and more 
> memory, but there are few.
>
> Feedback welcome,
>  Thomas Güttler
>

Hey

I wouldn't use this approach - caching in threadlocals is the wrong
place to cache. Primarily, this is because the cache is in the wrong
location - it is per thread, which means you must have n caches for n
threads. This is an inefficient use of memory, it would be better to
cache at a different level, eg memcached, redis, etc.

Secondly, this caching is very naïve. Queries are never evicted from
the cache, and so any updates to the underlying table will not be
reflected in versions that are cached. Different threads could then
cache different results for the same query, and you will end up with
heisenbugs - where the behaviour changes the closer you examine it.

You can fix all these issues by using a real cache engine like
memcached, set appropriate timeouts etc. Items retrieved from the
cache will be consistent, even amongst different threads. You can use
the query from the queryset as the key.

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: Relation not found error while dealing with foreign keys and forms

2011-11-03 Thread Furbee
I may have lead you astray. I set up the same models on my end and get the
same query; it didn't show the join of the foreign key in the QuerySet of
Staff, but when I did a get() on username='tsamuel' I got a Staff object.
Then I was able to get the group they belonged to. This was successful for
me:

Here's my data:

table: n_nics_groups
n_group_number; n_group_name
1; "TestGroup1"
2; "TestGroup2"
3; "TestGroup3"

table: n_test_staff
"tfigura";"";"";"";"";"";"";"";"";2;"";"''";"";"";"";1;1;1;;"''";"''";"''";"''";"";FALSE;TRUE
"tsamuel";"";"";"";"";"";"";"";"";1;"";"''";"";"";"";1;1;1;;"''";"''";"''";"''";"''";FALSE;TRUE

'tfigura' is in group with n_group_number 2, tsamuel is in group with
n_group_number 1.

python manage.py shell:
>>> from project.models import NICSGroupType, Staff
>>> i = Staff.objects.get(username='tsamuel')
>>> i.nics_group.n_group_name
>>> u'TestGroup1'

Is this operational for your instance? If not, I would double check that
the n_nics_groups table definitely exists in the datasource you defined as
'gold.' This should be defined in the DATABASES section of settings.py. It
looks like it is the database 'public' from your example, but double check
that the 'gold' DATABASE points there.

Otherwise, I wonder if it is somewhere where you are defining the form
object. First, let's verify that the foreign key reference is being honored
on your system, by running the above test, to verify that the group is
printed, when you get() a specific record and print the
nics_group.n_group_name.

Thanks,

Furbee

On Wed, Nov 2, 2011 at 5:09 PM, Tabitha Samuel wrote:

> Thank you so much for your reply! So I got a "Staff object has no
> attribute 'query'" error when I did it with the get. I got the sql
> when I tried it with the filter instead (instance =
> Staff.objects.using('gold').filter(username='tsamuel') >>
> str(instance.query))this is what I'm getting:
>
> 'SELECT "n_test_staff"."username", "n_test_staff"."home_phone",
> "n_test_staff"."cell_phone", "n_test_staff"."home_address",
> "n_test_staff"."home_city", "n_test_staff"."home_state",
> "n_test_staff"."home_zip", "n_test_staff"."emergency_name",
> "n_test_staff"."emergency_phone", "n_test_staff"."nics_group",
> "n_test_staff"."room_number", "n_test_staff"."title",
> "n_test_staff"."supervisor", "n_test_staff"."url",
> "n_test_staff"."im", "n_test_staff"."last_modification_time",
> "n_test_staff"."start_date", "n_test_staff"."creation_time",
> "n_test_staff"."termination_date", "n_test_staff"."bio",
> "n_test_staff"."photopath", "n_test_staff"."office_phone",
> "n_test_staff"."email", "n_test_staff"."preferred_name",
> "n_test_staff"."deleted", "n_test_staff"."viewable" FROM
> "n_test_staff" WHERE "n_test_staff"."username" = tsamuel '
>
> Looks like from the query, is not looking into the n_nics_groups
> table. Question is why?
>
> Tabitha
>
> On Nov 2, 6:00 pm, Furbee  wrote:
> > Can you try this and tell us what you see:
> >
> > Run a shell using python manage.py shell
> >
> > >>> instance = Staff.objects.using('gold').get(username='tsamuel')
> > >>> str(instance.query)
> >
> > This will tell us whether or not the database, reference, and such are
> > correctly translating into a query. The error means Django is sending an
> > erroneous query to your database layer.
> >
> > Furbeenator
> >
> > On Wed, Nov 2, 2011 at 1:54 PM, Tabitha Samuel  >wrote:
> >
> >
> >
> >
> >
> >
> >
> > > Hi,
> >
> > > In brief here is my problem. I have two simple tables, one has a one
> > > to many relation with the other. The problem I run into is that when I
> > > try to create a form instance of the child, and try to print it or
> > > render it in a template, I run into a "relation not found" error for
> > > the parent. Simply querying the parent works without a problem.
> >
> > > This is what my models.py looks like:
> > > from django.db import models
> >
> > > class NICSGroupType(models.Model):
> > > n_group_number = models.IntegerField(primary_key = True)
> > >n_group_name = models.CharField(max_length = 512)
> > >class Meta:
> > >db_table = "n_nics_groups"
> >
> > > class Staff(models.Model):
> > >username= models.CharField(primary_key = True,
> > > max_length = 50)
> > >home_phone  = models.CharField(max_length = 12,
> > > null=True)
> > >cell_phone  = models.CharField(max_length = 12,
> > > null = True)
> > >home_address= models.CharField(max_length = 1024,
> > > null = True)
> > >home_city   = models.CharField(max_length = 64,
> > > null = True)
> > >home_state  = models.CharField(max_length = 32,
> > > null = True)
> > >home_zip= models.CharField(max_length = 10,
> > > null = True)
> > >emergency_name  = models.CharField(max_length =64,
> > > null = True)
> > >emergency_phone = 

Re: User form creation from frontend?

2011-11-03 Thread J. Cliff Dyer
This is readily done in Django, but it will require you to handle the 
logic involved.  You will need to create a view that shows a data entry 
form to the user to create the quiz and processes the data that is 
submitted, and then to create another view where students see the 
homework questions and can submit answers.


You will want to look into the documentation on ModelForms for help in 
setting up the teacher quiz-creation view.


Cheers,
Cliff


On 11/03/2011 11:21 AM, Mauricio Mercado wrote:


I would like to be able to make a user create forms to a section of a 
site from the frontend, is there anything out there that would let me 
do this in Django/Python?


The point is to be able to create kind of quizzes section, or like 
homework questions to students, but the teacher who creates such 
things should be able to create this forms from the frontend, because 
he should not be able to go into the admin site.


Thank you all.


Mauricio Mercado
Electronics Engineer
System Administrator - Python Developer


Web :http://flavors.me/maumercado 
Email :maumerc...@gmail.com 


___
Colombia, Bogota D.C.

--
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: Caching at model class level

2011-11-03 Thread Andre Terra
Django caching frameworks also provide a low level API[1].

sebleier's django-redis-cache is one great tool for the job [2]. In order
to use it, you will of course need redis too [3].


Cheers,
AT

[1]
https://docs.djangoproject.com/en/dev/topics/cache/#the-low-level-cache-api
[2] https://github.com/sebleier/django-redis-cache
[3] http://redis.io



On Thu, Nov 3, 2011 at 1:33 PM, Thomas Guettler  wrote:

> Am 03.11.2011 15:29, schrieb Donald Stufft:
> >  Normally this is cached using the Django caching framework, this lets
> > you save it in memcache, redis, etc
>
> The django caching frameworks provides decorators for caching complete
> web pages. And it provides an API for caching strings or objects which can
> get pickled.
>
> It does not provide caching at object level, if new query sets get used
> (like related
> object look-up).
>
> Try it yourself. This middleware shows how many times the same SQL query
> was executed:
>
> http://djangosnippets.org/snippets/344/
>
>
>  Thomas
>
> > On Thursday, November 3, 2011 at 10:22 AM, Thomas Guettler wrote:
> >
> >> Hi,
> >>
> >> I try to reduce the number of db-queries in my app.
> >>
> >> There is a model which changes almost never. It is like a "type of
> ticket"
> >> in a trouble ticket system.
> >>
> >> On one page there are seven SQL-Queries (SELECT  FROM ticket_type
> >> where id=123) which of course always return
> >> the same result.
> >>
> --
> Thomas Guettler, http://www.thomas-guettler.de/
> E-Mail: guettli (*) thomas-guettler + de
>
> --
> 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: Caching at model class level

2011-11-03 Thread Thomas Guettler
Am 03.11.2011 15:29, schrieb Donald Stufft:
>  Normally this is cached using the Django caching framework, this lets
> you save it in memcache, redis, etc

The django caching frameworks provides decorators for caching complete
web pages. And it provides an API for caching strings or objects which can get 
pickled.

It does not provide caching at object level, if new query sets get used (like 
related
object look-up).

Try it yourself. This middleware shows how many times the same SQL query was 
executed:

http://djangosnippets.org/snippets/344/


  Thomas

> On Thursday, November 3, 2011 at 10:22 AM, Thomas Guettler wrote:
> 
>> Hi,
>>
>> I try to reduce the number of db-queries in my app.
>>
>> There is a model which changes almost never. It is like a "type of ticket"
>> in a trouble ticket system.
>>
>> On one page there are seven SQL-Queries (SELECT  FROM ticket_type
>> where id=123) which of course always return
>> the same result.
>>
-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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



User form creation from frontend?

2011-11-03 Thread Mauricio Mercado
I would like to be able to make a user create forms to a section of a site from 
the frontend, is there anything out there that would let me do this in 
Django/Python?

The point is to be able to create kind of quizzes section, or like homework 
questions to students, but the teacher who creates such things should be able 
to create this forms from the frontend, because he should not be able to go 
into the admin site.

Thank you all.


Mauricio Mercado
Electronics Engineer
System Administrator - Python Developer 


Web : http://flavors.me/maumercado
Email : maumerc...@gmail.com


___
Colombia, Bogota D.C.

-- 
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 at model class level

2011-11-03 Thread Donald Stufft
Normally this is cached using the Django caching framework, this lets you save 
it in memcache, redis, etc  


On Thursday, November 3, 2011 at 10:22 AM, Thomas Guettler wrote:

> Hi,
>  
> I try to reduce the number of db-queries in my app.
>  
> There is a model which changes almost never. It is like a "type of ticket"
> in a trouble ticket system.
>  
> On one page there are seven SQL-Queries (SELECT  FROM ticket_type where 
> id=123) which of course always return
> the same result.
>  
> I want to cache the objects:
>  
> t1=TicketType.objects.get(id=123)
> t2=TicketType.objects.get(id=123)
>  
> t1 and t2 should be the identical python object, not just objects containing 
> the same data.
>  
> Has someone done this before?
>  
> Here is my first version:
>  
> class ThreadLocalQueryset(models.query.QuerySet):
> _threadlocal=threading.local()
> _threadlocal.cache=dict() # The cache is at class-level. It survives a 
> request.
> def get(self, **kwargs):
> kwargs_tuple=tuple(kwargs.items())
> obj=self._threadlocal.cache.get(kwargs_tuple)
> if obj is not None:
> return obj
> obj=models.query.QuerySet.get(self, **kwargs)
> self._threadlocal.cache[kwargs_tuple]=obj
> return obj
>  
> class ThreadLocalManager(models.Manager):
> use_for_related_fields = True
> def get_query_set(self):
> return ThreadLocalQueryset(self.model, using=self._db)
>  
> class TicketType(models.Model):
> objects=ThreadLocalManager()
>  
> If there would be many TicketTypes, the interpreter would use more and more 
> memory, but there are few.
>  
> Feedback welcome,
> Thomas Güttler
>  
> --  
> Thomas Guettler, http://www.thomas-guettler.de/
> E-Mail: guettli (*) thomas-guettler + de
>  
> --  
> 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 
> (mailto:django-users@googlegroups.com).
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com 
> (mailto: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.



Caching at model class level

2011-11-03 Thread Thomas Guettler
Hi,

I try to reduce the number of db-queries in my app.

There is a model which changes almost never. It is like a "type of ticket"
in a trouble ticket system.

On one page there are seven SQL-Queries (SELECT  FROM ticket_type where 
id=123) which of course always return
the same result.

I want to cache the objects:

t1=TicketType.objects.get(id=123)
t2=TicketType.objects.get(id=123)

t1 and t2 should be the identical python object, not just objects containing 
the same data.

Has someone done this before?

Here is my first version:

class ThreadLocalQueryset(models.query.QuerySet):
_threadlocal=threading.local()
_threadlocal.cache=dict() # The cache is at class-level. It survives a 
request.
def get(self, **kwargs):
kwargs_tuple=tuple(kwargs.items())
obj=self._threadlocal.cache.get(kwargs_tuple)
if obj is not None:
return obj
obj=models.query.QuerySet.get(self, **kwargs)
self._threadlocal.cache[kwargs_tuple]=obj
return obj

class ThreadLocalManager(models.Manager):
use_for_related_fields = True
def get_query_set(self):
return ThreadLocalQueryset(self.model, using=self._db)

class TicketType(models.Model):
objects=ThreadLocalManager()

If there would be many TicketTypes, the interpreter would use more and more 
memory, but there are few.

Feedback welcome,
  Thomas Güttler

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

-- 
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 and profile pictures creation

2011-11-03 Thread yan
Hello, I am developing a website which will have some social features
like people profiles, but I am having a problem on how to create a
space where a person will put his/her profile picture, I am using
django framework and MySQL, can anyone help me please?

-- 
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: QuerySet: "if obj in queryset" can be very slow

2011-11-03 Thread Tom Evans
On Wed, Nov 2, 2011 at 6:26 PM, Ian Clelland  wrote:
> Just looking at the source to QuerySet (finally), and it looks like the
> __contains__ method actually does something different than this: It
> evaluates the whole QuerySet in bulk at the database level, and starts
> creating model instances based on that, but only until it finds a matching
> one. So, after running "if obj in qs", you might end up with one object
> created, or you might end up with 70M objects, or anywhere in between.
> Again: odd, undocumented, and potentially surprising behaviour, and I'd
> recommend explicit over implicit, especially in this case.
>

I disagree. All of this behaviour is documented in my mind:

It is documented here when querysets are evaluated:

https://docs.djangoproject.com/en/1.3/ref/models/querysets/#when-querysets-are-evaluated

It's documented here that iterating through a queryset will cache the
objects created:

https://docs.djangoproject.com/en/1.3/ref/models/querysets/#iterator

It's documented here that testing for results is slightly quicker than
evaluating and testing the queryset:

https://docs.djangoproject.com/en/1.3/ref/models/querysets/#exists

It's documented here that caching is optimistic - it caches the
results that have been requested:

https://docs.djangoproject.com/en/1.3/topics/db/queries/#caching-and-querysets

Do we really need to specifically point out that the __contains__
method iterates through the queryset and stops when it finds an
answer?

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: Abstract FormView

2011-11-03 Thread Andre Terra
All you have to do is create a MyFormMixin class and add all those methods
you want to override. Usually you will want to call super() on the class so
that the normal behavior is also present in your final class.

The difference between a Mixin and a full-fledged Class can be nearly
non-existent in some cases, so don't worry about the terminology. If you
want, you can even subclass 'object' to make it as generic as it gets.


# example.py

class MyFormMixin(object):
def get_form_kwargs(self, *args, **kwargs):
kw = super(MyFormMixin, self).get_form_kwargs(*args, **kwargs)
kw.update({'some': 'extra', 'permantent': 'kwargs'})
return kw

class MyViewWithMixin(MyFormMixin, FormView):
pass

# end example.py

Hope that helps! Let us know if you have any other questions.


Cheers,
AT


On Wed, Nov 2, 2011 at 6:47 PM, Kurtis  wrote:

> Hey,
>
> I have a couple of FormViews that override quite a few methods. I want
> to write an "Abstract View" that I can subclass for these. I'm
> guessing what I actually need is a custom Mixin but I'm really not
> sure.
>
> Any suggestions on how to go about doing this?
>
> Some methods I'm overriding:
>
> get_form_kwargs
> form_valid
> form_invalid
> get_context_data
>
> Other than the form_class, the code in each is the same line for line
> (except of course when referencing the Class 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
> 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: I've done my first project in django but now I can't start a new one.. ?!

2011-11-03 Thread Andre Terra
You've probably changed your .py file association in Explorer, probably
when configuring Notepad++.

Try changing them back so that python executes .py files or  run

> python django-admin.py startproject todo


Cheers,
AT



On Thu, Nov 3, 2011 at 4:58 AM, paz aricha  wrote:

> I finished the ThinkVitamin tutorial on the polls app and now I want
> to start a new project to work on.
> So I opened my command line (on windows) and types:
> "django-admin.py startproject todo"
> But it didn't work...Instead it just opens the django-admin.py file
> in
> notepadd++ and does nothing else.
> Have you encountered such problem? how do I solve this?
>
> Thanks and Sorry if this is a newb question.
> Paz.
>
> --
> 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: Suggestions on "Loading" for possible long load-times?

2011-11-03 Thread Andre Terra
What Matt meant to say is that Celery is *the* framework for handling
background tasks, especially in the Python/Django world.


Cheers,
AT

On Wed, Nov 2, 2011 at 8:55 PM, Matt Schinckel  wrote:

> Russ mentioned it in passing, but I'll point it out for clarity: Celery is
> a great framework for handling background tasks.
>
> --
> 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/-/TwtPwcwjzvkJ.
>
> 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.



I've done my first project in django but now I can't start a new one.. ?!

2011-11-03 Thread paz aricha
I finished the ThinkVitamin tutorial on the polls app and now I want
to start a new project to work on.
So I opened my command line (on windows) and types:
"django-admin.py startproject todo"
But it didn't work...Instead it just opens the django-admin.py file
in
notepadd++ and does nothing else.
Have you encountered such problem? how do I solve this?

Thanks and Sorry if this is a newb question.
Paz.

-- 
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: "python manage.py runserver" creates not tables (tutorial)

2011-11-03 Thread Andre Terra
$ python manage.py dbshell

If you can't reach a database shell through that, then there's something
wrong with your database setup.


Cheers,
AT

On Wed, Nov 2, 2011 at 10:55 AM, Martin Chiteri wrote:

> What about if you do a
>
> python manage.py sqlall
>
> From the settings file, I do not see any of your apps added in the
> list of installed apps, like
>
> INSTALLED_APPS = (
>   'django.contrib.auth',
>'mysite.news',
> .,
> )
>
> Martin.
>
> --
> 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: QuerySet: "if obj in queryset" can be very slow

2011-11-03 Thread Thomas Guettler
Hi,

I created a ticket:

https://code.djangoproject.com/ticket/17156

{{{
The documentation should explain what happens in this code:

if obj in queryset:


If queryset is huge, the above code can be very slow.

If you want to run the code in the database, you should use this:

if queryset.filter(pk=obj.pk).exists():


Related discussion:  
http://groups.google.com/group/django-users/browse_thread/thread/5a8196ff1086f4ae/530548a127a6e3ca

Can someone please provide a patch for the documentation. I am not a native 
speaker, and won't find the right words.
}}}


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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