Re: newbie problem with accepting form input

2010-12-13 Thread john doe
On Mon, Dec 13, 2010 at 6:12 PM, Titan, Jer-ming Lin wrote:

> Hi John,
>
>  each element in the choices is a two elements tuple. first one is
> the real data will be saved in the database and second one will
> present on the form. therefore, the max_length of 'type' field must be
> modified to fit the first element in the choices tuple. Plz see the
> following code, i change the first element and the type field's
> max_length.
>
>  REPORT_CHOICES = (
>('BR', 'Bug Report'),
>('UN', 'Unknown Problem'),
>)
>  type = models.CharField(max_length=2, choices=REPORT_CHOICES)
>
Hi Titan, thank you. Yes that was something I could correct.

However the problem of the error which says "Select a valid choice. SF: Seg
Fault is not one of the available choices."
still remains. Any insight here?


>  ps: you can also google some pages which use the IntegerField to
> save the choices.
>
> BR
> Titan
>
> On Dec 14, 9:04 am, john doe  wrote:
> > Dear all,
> >I am making a small Django app for a bug tracking system to get my
> > head round this awesome framework. I am facing a problem wherein when
> > accepting input via a form generated by models. The classes are listed
> below
> > (not in its entirety).
> >
> > [code]
> > class Report(models.Model):
> >   #type = models.CharField(max_length=200)
> >   REPORT_CHOICES = (
> > ('BR: Bug Report', 'Bug Report'),
> > ('UN: Unknown Problem', 'Unknown Problem'),
> > )
> >   type = models.CharField(max_length=1, choices=REPORT_CHOICES)
> >   submitter = models.CharField(max_length=200, default='Anonymous')
> > ...
> > ...
> > class Incident(models.Model):
> >   report = models.ForeignKey(Report)
> >   INCIDENT_CHOICES = (
> > ('SF: Seg Fault', 'SegFault'),
> > ('ML: Memory Leak', 'Memory Leak'),
> > ('MC: Memory Corruption', 'Memory Corruption'),
> >   )
> >   type = models.CharField(max_length=1, choices=INCIDENT_CHOICES)
> >   #description of the incident
> >   description = models.CharField(max_length=2)
> > ...
> > ...
> > [/code]
> >
> > I have generated a form wherein a user can enter a report, and multiple
> > incidents related to the report. When I use the function to accept the
> > input, not actually processing anything I get "Select a valid choice. SF:
> > Seg Fault is not one of the available choices." .
> >
> > The HTML page code looks like below:
> > [code]
> > Submit a report
> > {% if new_report_form %}
> > 
> > 
> > {{ new_report_form.non_field_errors }}
> > 
> > {{ new_report_form.type.errors }}
> > Type of Report:
> > {{ new_report_form.type }}
> > 
> >
> > {{ new_incident_form.type.errors }}
> > Type of Incident:
> > {{ new_incident_form.type }}
> > 
> > ...
> > ...
> > [/code]
> >
> > The form.is_valid() call is basically saying that there's a problem with
> > validating the form input because the choice selected for the
> incident-type
> > is not valid. However, in the model description, the choices are clearly
> > valid and in the form I have different identifiers too. Can someone
> please
> > provide some advice as to why this might be happening.
> >
> > Thanks in advance.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



replacing integer with tuple value in template

2010-12-13 Thread morgand
I have a tuple set

MY_TYPE = (
(0, 'Other'),
(1, 'This'),
(2, 'That'),
)

In my model I have a field that uses "choices" to set the value. Can
save/edit the model as  a modelform fine.

But I want to display a LIST of my records and replace the integer
with the respective text ..

so...

mylist = MyClass.objects.filter(key=lookup_value)

I can display the list, but it displays the integer value rather than
the "text" that I want. Help!!

In the template entering I have {% myObject.type %} which gives me the
0,1,2 etc...

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



Re: I don't get the big picture (admin, etc.)

2010-12-13 Thread Christophe Pettus

On Dec 13, 2010, at 7:25 PM, cocolombo wrote:
> 1) Should the players use the admin to loggin ?

I think that there's a good hint given by the is_staff property of a User.  The 
admin is best used by people you would consider "staff," rather than general 
users of the site.  While it is certainly possible to lock the admin down 
pretty thoroughly, it's much better to design the public-facing part of your 
site from scratch, rather than worry about bending the admin to being a good 
public interface, and locking it down completely against mischief.

> 2) Do I use the user objects, to keep information about each players ?
> Or a different class called player ?

Either way has its merits.  There's no reason not to use the User auth system 
even for people who don't use the admin; it's quite flexible.

> 3) Should I create a separate application for the login section of the
> site ?

In general, yes, that's a good idea.  The user login section is an isolatable 
bit of code that makes perfect sense as an application.

> 4) Is registering a new user (confirmation by email, etc) a different
> module or is it part in the admin.

It's part of the application you built up in #3. :)

> 5) I understand the importance of admin to manage my  database, but of
> course, I don't want the players to access directly the database. Do
> the players access the admin with limited privileges, or do they not
> touch the admin whatsoever ?

See #1.  It's far easier to build up the public facing part of the site with 
what users *can* do, than worry about having missed something in the admin that 
they *can* do.

--
-- Christophe Pettus
   x...@thebuild.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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: I don't get the big picture (admin, etc.)

2010-12-13 Thread Venkatraman S
On Tue, Dec 14, 2010 at 8:55 AM, cocolombo  wrote:

> I read a lot of documentation and books but there are still some very
> basic things that I just don't catch about Django.
>

The docs and we are here to help :) But only if you spend sometime learning
the bits yourselves.

>
> 1) Should the players use the admin to loggin ?
>

You can use the user-auth system in place.
http://docs.djangoproject.com/en/dev/topics/auth/


>
> 2) Do I use the user objects, to keep information about each players ?
> Or a different class called player ?
>

You can use the Users object. If the player is different from that of a
User, then you may create additional
objects suitably - totally depends on how you have structured your game.


> 3) Should I create a separate application for the login section of the
> site ?
>

Check #1.


>
> 4) Is registering a new user (confirmation by email, etc) a different
> module or is it part in the admin.
>

Refer django-registration


> 5) I understand the importance of admin to manage my  database, but of
> course, I don't want the players to access directly the database. Do
> the players access the admin with limited privileges, or do they not
> touch the admin whatsoever ?
>

django-Admin doesnt manage your database - it provides an interface to look
into what your schema contains.

As I said I read a lot, but I am stucked and don't understand the "big
> picture" of an application (or is it a project) ans it's relation with
> the admin.
>

Did you try creating your app?

Check out http://lightbird.net/dbe/ for more.

-V
http://blizzardzblogs.blogspot.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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



I don't get the big picture (admin, etc.)

2010-12-13 Thread cocolombo
I read a lot of documentation and books but there are still some very
basic things that I just don't catch about Django.

Let's say I want to crate a very basic site for a simple game with no
graphics, just text.

1) Should the players use the admin to loggin ?

2) Do I use the user objects, to keep information about each players ?
Or a different class called player ?

3) Should I create a separate application for the login section of the
site ?

4) Is registering a new user (confirmation by email, etc) a different
module or is it part in the admin.

5) I understand the importance of admin to manage my  database, but of
course, I don't want the players to access directly the database. Do
the players access the admin with limited privileges, or do they not
touch the admin whatsoever ?

As I said I read a lot, but I am stucked and don't understand the "big
picture" of an application (or is it a project) ans it's relation with
the admin.

Thanks for taking the time to answer such questions that must be so
trivial to many of you.

cocolombo

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



Re: newbie problem with accepting form input

2010-12-13 Thread Titan, Jer-ming Lin
Hi John,

  each element in the choices is a two elements tuple. first one is
the real data will be saved in the database and second one will
present on the form. therefore, the max_length of 'type' field must be
modified to fit the first element in the choices tuple. Plz see the
following code, i change the first element and the type field's
max_length.

  REPORT_CHOICES = (
('BR', 'Bug Report'),
('UN', 'Unknown Problem'),
)
  type = models.CharField(max_length=2, choices=REPORT_CHOICES)

  ps: you can also google some pages which use the IntegerField to
save the choices.

BR
Titan

On Dec 14, 9:04 am, john doe  wrote:
> Dear all,
>        I am making a small Django app for a bug tracking system to get my
> head round this awesome framework. I am facing a problem wherein when
> accepting input via a form generated by models. The classes are listed below
> (not in its entirety).
>
> [code]
> class Report(models.Model):
>   #type = models.CharField(max_length=200)
>   REPORT_CHOICES = (
>         ('BR: Bug Report', 'Bug Report'),
>         ('UN: Unknown Problem', 'Unknown Problem'),
>     )
>   type = models.CharField(max_length=1, choices=REPORT_CHOICES)
>   submitter = models.CharField(max_length=200, default='Anonymous')
> ...
> ...
> class Incident(models.Model):
>   report = models.ForeignKey(Report)
>   INCIDENT_CHOICES = (
>         ('SF: Seg Fault', 'SegFault'),
>         ('ML: Memory Leak', 'Memory Leak'),
>         ('MC: Memory Corruption', 'Memory Corruption'),
>   )
>   type = models.CharField(max_length=1, choices=INCIDENT_CHOICES)
>   #description of the incident
>   description = models.CharField(max_length=2)
> ...
> ...
> [/code]
>
> I have generated a form wherein a user can enter a report, and multiple
> incidents related to the report. When I use the function to accept the
> input, not actually processing anything I get "Select a valid choice. SF:
> Seg Fault is not one of the available choices." .
>
> The HTML page code looks like below:
> [code]
> Submit a report
> {% if new_report_form %}
>     
>     
>         {{ new_report_form.non_field_errors }}
>     
>             {{ new_report_form.type.errors }}
>                 Type of Report:
>                 {{ new_report_form.type }}
>             
>    
>             {{ new_incident_form.type.errors }}
>                 Type of Incident:
>                 {{ new_incident_form.type }}
>             
> ...
> ...
> [/code]
>
> The form.is_valid() call is basically saying that there's a problem with
> validating the form input because the choice selected for the incident-type
> is not valid. However, in the model description, the choices are clearly
> valid and in the form I have different identifiers too. Can someone please
> provide some advice as to why this might be happening.
>
> Thanks in advance.

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



redirects and ipv6

2010-12-13 Thread Michael P. Soulier
Hi,

We're enabling ipv6 on a server and finding that redirects in django are
broken. The host portion is being truncated.

Is this a known problem?

Thanks,
Mike
-- 
Michael P. Soulier 
"Any intelligent fool can make things bigger and more complex... It takes a
touch of genius - and a lot of courage to move in the opposite direction."
--Albert Einstein


signature.asc
Description: Digital signature


Showing some extra HTML in a ModelForm

2010-12-13 Thread Elmar A.
Hi

I'd like to add some additional HTML to to a model form in the admin
backend. This HTML does not have any relevant form-functionality, i.e.
it should just be displayed for the user.

But I need the model instance to create the HTML. Basically, I want to
fetch some images and show them to the user. Theses images should be
located in a folder derived from a property of the model instance.

Now I'm wondering what's the best way to do it (maybe I'm just
over-engeneering here…):
- adding some dummyfield with a widget rendering to the html I want. A
formfield is not designed to do this
- creating a widget rendering the formelement + my html. But I want to
decide where to place this html
- extending the override the ModelForm's as_p etc. methods: not very dry
- ?

In all cases I'm not sure how to access the model, too.
Formfields/Widgets do not have access to the model instance itself,
just to their corresponding value, do they?

So, if I missed something in the docs, just point me there. Any hints
appreciated.

Thanks in advance
Elmar

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



newbie problem with accepting form input

2010-12-13 Thread john doe
Dear all,
   I am making a small Django app for a bug tracking system to get my
head round this awesome framework. I am facing a problem wherein when
accepting input via a form generated by models. The classes are listed below
(not in its entirety).

[code]
class Report(models.Model):
  #type = models.CharField(max_length=200)
  REPORT_CHOICES = (
('BR: Bug Report', 'Bug Report'),
('UN: Unknown Problem', 'Unknown Problem'),
)
  type = models.CharField(max_length=1, choices=REPORT_CHOICES)
  submitter = models.CharField(max_length=200, default='Anonymous')
...
...
class Incident(models.Model):
  report = models.ForeignKey(Report)
  INCIDENT_CHOICES = (
('SF: Seg Fault', 'SegFault'),
('ML: Memory Leak', 'Memory Leak'),
('MC: Memory Corruption', 'Memory Corruption'),
  )
  type = models.CharField(max_length=1, choices=INCIDENT_CHOICES)
  #description of the incident
  description = models.CharField(max_length=2)
...
...
[/code]

I have generated a form wherein a user can enter a report, and multiple
incidents related to the report. When I use the function to accept the
input, not actually processing anything I get "Select a valid choice. SF:
Seg Fault is not one of the available choices." .

The HTML page code looks like below:
[code]
Submit a report
{% if new_report_form %}


{{ new_report_form.non_field_errors }}

{{ new_report_form.type.errors }}
Type of Report:
{{ new_report_form.type }}

   
{{ new_incident_form.type.errors }}
Type of Incident:
{{ new_incident_form.type }}

...
...
[/code]

The form.is_valid() call is basically saying that there's a problem with
validating the form input because the choice selected for the incident-type
is not valid. However, in the model description, the choices are clearly
valid and in the form I have different identifiers too. Can someone please
provide some advice as to why this might be happening.

Thanks in advance.

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



Utility of select_related when rendering ForeignKeys in a form? [Developer eyes appreciated]

2010-12-13 Thread Margie Roginski
Could someone with some developer background take a look at my
question below and let me know if my understanding is correct?

Let's say I have a Task model that contains a foreign key to a User:

class Task(models.Model)
owner = models.ForeignKey('auth.User')

Now let's say I have a ModelForm that contains this owner field.  When
I render that form for an instance of a task, the django method
models_to_dict() is called to get the initial values for the task.
For my owner field, it sets the initial value to the numeric id of the
user.

This seems to negate any utility of select_related() when I am later
rendering my form.  For example, if my task is retrieved through a
query and I have select_related set to 1, that query will do an extra
lookup so that the owner's first name and last name are available with
no additional sql query, assuming I am accessing them from the
instance that the intial query returned. However, when I am rendering
my form, the value passed in is just the id of the user, ie '1'.  So
my widget must now do a new lookup to get the actual user in order to
print the first name and last name.

Can anyone comment on whether my understanding is correct?  Should I
simply not be using select_related in this situation?  Is it primarily
intended for use from views.py, where you have more control over
exactly how and when you reference the attributes of a model
instance?  Or is there some better way I could be making use of it?

Thank you!

Margie


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



Re: __init__.py file executed twice ?

2010-12-13 Thread Mike Dewhirst
On Dec 13, 10:57 am, martvefun  wrote:
> On 10-12-10 11:09, Mike Dewhirst wrote:
> > On 10/12/2010 7:43pm, martvefun wrote:
> >> On 09-12-10 01:37, Mike Dewhirst wrote:
> >>> It seems like a good place to put it. Maybe you can test to see if the
> >>> threads have been started already?



> Thank you, it works if I have to call in the same files (like s1 =
> singleton() ; s2 = singleton() ) but here I still have two calls
>
> class singleton(object):
>      """ designed by Oren Tirosh and Jeff Pitman """
>      def __new__(self, *args, **kwargs):
>          print "call singleton"
>          if not '_singleton' in self.__dict__:
>             print "first time created"
>             slate = object.__new__(self)
>             slate.state = {
>                 'threads':True,
>                 # add other state things as required
>             }
>             self._singleton = slate
>          return self._singleton
>
> singleton()
> print "Server is now runing"
>
> gives me :
> $ python manage.py runserver
> call singleton
> first time created
> Server is now runing
> call singleton
> first time created
> Server is now runing
> Validating models...
> 0 errors found

I just tested it myself and while it definitely works - meaning it
does return exactly the same object each time - manage.py runserver
apparently starts the framework twice. Hence you see it twice. I
noticed that when you edit a file and the dev server automatically
restarts, the singleton gets recreated but only once as expected.

Here is some research by Graham Dumpleton earlier this year and which
explains the process in detail ...

http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html

If you decide to use a singleton to monitor state you might have to
look for somewhere safe to start it.

>
> And anyway I just realised another problem : I'll need to have access to
> the objects I created from views.

I think it would work from anywhere you can call the code but you need
to test it.

Mike

> The idea is to send a message to the thread when a certain action is
> done (like user registration, validate choices...) but to do that I need
> an access to this object (I cannot create another one because of
> concurrency safety)
>
> Any idea ?

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



Re: ForeignKey search

2010-12-13 Thread Daniel Roseman
On Monday, December 13, 2010 2:54:12 PM UTC, Michele JD Granocchia
wrote:(django 1.2)
Hi, i need to do the following:

Class 1, with a field called "field1" (CharField)
Class 2, with a field called "fieldwfk" (ForeignKey)

User enters a text and submits, which goes into "searchtext"

--- searchtext = request.GET.get('text')

Now i want to get all Class2 objects WHERE fieldwfk CONTAINS
searchtext.

With the following code:

--- class1s =
Class1.objects.filter(field1__icontains=searchtext)
--- cl2 =
Class2.objects.filter(fieldwfk__id=clienteric).order_by('-id')

or even with the following code:

--- class1s =
Class1.objects.get(field1__icontains=searchtext)
--- cl2 =
Class2.objects.filter(fieldwfk__id=class1s.id).order_by('-id')

I get what i want, but...
only if class1s matches only 1 record...
otherwise i get

--- Caught OperationalError while rendering: (1242, 'Subquery returns
more than 1 row')

in the first case
and

--- get() returned more than one Clienti -- it returned 3! Lookup
parameters were {'nomecliente__icontains': u'ca'}

in the second.

Plz help me... T_T


Why not just:


cl2 =
Class2.objects.filter(fieldwfk__field1__icontains=searchtext).order_by('-id')
--
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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Conditional inline for django admin

2010-12-13 Thread Nick
I am working with an app that has several different models that are
connected to a central model via a ForiegnKey.

I'd like to display a certain inline based on a value from the central
model.

Ex.

model1
some_field
central = ForeignKey(CentralModel)

model2
some_field
central = ForeignKey(CentralModel)

CentralModel
type_field

In the admin:

if self.type == '1':
inlines = [
model1
]

else:
inlines = [
model2
]

I'm looking at overriding the get_formsets method but is taht the way
to go?

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



Re: Paginator and foreign key

2010-12-13 Thread refreegrata
thanks for the answer, but the solution don't show anything. I must be
doing something wrong.
if now I have
---
class Myline(models.mode):
   fk_myDoc = models.ForeignKey(MyDoc, related_name="")
---

How Can I use {% for line doc.X_set.all %} in the template?
I'm sorry for this asking, but I can't find the _set.all option in the
Django documentation.

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



Any Python/Django developers in Silicon Valley?

2010-12-13 Thread MichelleAtTEK
Hi All,

 I am looking to network with Python/Django users in the South bay
area for a long ter/FT opportunity. If you or anyone you know has 3+
years of experience with Python I would like to talk if for nothing
more than networking. If interested please give me a call at
408.367.6833 or em mbennett at teksystems.com

Thank you!

Regards,

Michelle

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



Re: Paginator and foreign key

2010-12-13 Thread bruno desthuilliers
On 13 déc, 16:59, refreegrata  wrote:
> Hello list, I have a question. Take a look to the next models.
> 
> class MyDoc(models.Model):
>     code = models.BigIntegerField()
>
> class Myline(models.mode):
>    fk_myDoc = models.ForeignKey(MyDoc)
> ---
>
> In my view I do something like
>
> myPaginator = Paginator(MyDoc.objects.filter(codigo=1), 10)
> myDocs = myPaginator.page(page_number)
>
> This return all the Docs with a code=1, but I too want to return all
> the objects with the type "MyLine" associated to the results of this
> query.

for doc in myDocs.object_list:
print doc.MyLine_set.all()


or in your template:


{% for doc in myDocs.object_list %}
  
 {{ doc.code }}
 
   {% for line doc.MyLine_set.all %}
   {{ line }}
   {% endfor %}
 
   
{% endfor %}


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



Re: Question on passing user to model objects

2010-12-13 Thread Scoox
Hi Daniel,

> However, calling foo.bar_set multiple times does *not* get the same
> queryset each time.
Okay, that was new to me :-)... Do you know what the reason for that
is?


> I discuss this a little in a blog
> entry 
> here:http://blog.roseman.org.uk/2010/01/11/django-patterns-part-2-efficien...
Thanks! I thank that is exactly what I want to achieve. I changed
_related_items to related_items (else Django would give me an error).

The data should now be correct.

I have a little problem passing the dict to the template though. When
I did so, the template would have the keys - not the actual values.

I also added:
obj_arr=[]
for key, obj in obj_dict.items():
obj_arr.append(obj)

It's not very beautiful, but keeps the designer from using {% for
key,value in dictionary.items %}{{ value }}{% endfor %}


> Does this necessarily need to be a model method? Why not a custom
> template tag or filter, that you can pass the request.user object to?
Then the filter would have to be inserted everywhere where any of the
object's attributes should be shown (the edit button is shown for each
visible attribute).




Thanks a lot!
Stephan

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



Re: Paginator and foreign key

2010-12-13 Thread refreegrata
if I return another list:
---
for i in range(len(paginatorDocs.object_list)):
resultados = {'myDoc': paginatorDocs.object_list[i],
  'myLines':
Myline.objects.filter(fk_myDoc=paginatorDocs.object_list[i].id),}

---
With this I can get the values, but I'm not sure if this is the best
way to solve the problem

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



form upload field and form validation

2010-12-13 Thread Daniel Carvalho
hi
I have a form with a file upload field.

If the form fails validation, the user has to give all the file fields
another time.


Someone told me it is possible to avoid that but I can't find more
information...

There was a thread about this before:
http://groups.google.com/group/django-users/browse_thread/thread/c09935490a56256f/ecda5197f7f60654?hl=en=gst=form+upload+remember+field#ecda5197f7f60654
"""
If you search in the archives, I seem to remember some people came up
with ways to pass the filename back in any case for manual display if
you want that, but it still won't be submitted as part of them form.
"""

couldn't find it. Anyone knows?





signature.asc
Description: OpenPGP digital signature


Re: Bringing down a website

2010-12-13 Thread Shamail Tayyab
Hi,

   Yes, we are using S3 for data. Actually its more related to load
testing..

We are firing requests from another machine at Amazon and trying to
attain an image quality vs size graph. Our quality of service depends
on this data.

@paul yes, that sounds nice.

On Dec 13, 8:43 pm, Paul Winkler  wrote:
> On Dec 13, 10:20 am, Shamail Tayyab  wrote:
>
> > What could be the simplest way to do it without altering any of my
> > current views or anything?
>
> Write a view for /shutdown which sets some global flag eg. in the
> database,
> then write some middleware to do the 
> rest:http://docs.djangoproject.com/en/dev/topics/http/middleware/

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



Re: Bringing down a website

2010-12-13 Thread creecode
Hello Shamail,

If you're running mod-wsgi you could try a variation on this technique
from the folks over at Caktus Consulting Group.

On Dec 13, 7:20 am, Shamail Tayyab  wrote:

> I am planning to write a handler like /shutdown which will ask me a
> password and once down, all the pages will just return an HTTP 503.
>
> What could be the simplest way to do it without altering any of my
> current views or anything?

Toodle-loo.
creecode

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



Re: Question on passing user to model objects

2010-12-13 Thread Scoox
> >     isEditable=0
> >     login=0
>
> Assuming these two previous lines are at the top-level of you class
> statement, both attributes will be class-attributes (that is "shared
> by all instances"). I don't think this is what you want.
Yes but that's what I intended. They should (and do) not all have the
same value, but every instance of the object should have access to the
user. Ideally I would have a static user class holding the current
user (or global variable), but unfortunately I could not get that to
work.

> >     def editable(self):
> >         if self.login==0: return False
> >         else:
> >             if self.isEditable!=0: return self.isEditable
> >             if self==self.login.get_profile():
>
> Are you sure you want to compare the current whatever instance with a
> profile ???

Nope, absolutly not :-). That should mean self.user instead of self.
In the company self is right since it extends the user, but here I
changed it.


> >                 self.isEditable=True
> >                 for o in self.offer_set.all(): o.editable=True
>
> Such a side-effect is really really bad practice (and, in this case,
> mostly useless).
I agree it's kind of bad.


> >                 return True
> >             else:
> >                 self.isEditable=False
> >                 return False
>
> Code depending on the request.user should either takes an user as
> param or live elsewhere.

I will put it somewhere else. I guess you mean because the code is re-
used twice.


> > (I added the isEditable attribute to cache if the object is editable,
> > since I wasn't sure if get_profile() is lazy loaded or sends a request
> > to the db with each iteration)
>
> When you aren't sure, check, don't wildguess.

Will do as soon as I am a little more used to Django.

> > Yes that sounds possible. Just wondering if there is a cleaner way to
> > do it - the ideal way would of course every object having access to
> > the user in some way, but that seems impossible.
>
> Indeed. How would your code work in another environnment (command line
> tool for example) else ?

There it worked fine (the original version, as you stated this one had
a bug). So it really must be the a different queryset.

> wrt/ "a cleaner way to do it", your business rules are not clear
> enough to come with a sensible answer.

What I am trying to archive is rather simple - I just did not figure
out a simple and clean way to do it:

I have the company and offer objects. Each offer belongs to a company
which belongs to a user. Whatever user is logged in should see an
"edit" link on the live site, whenever his own company or offers come
up. Anoynmous users should not see any edit links.

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



Paginator and foreign key

2010-12-13 Thread refreegrata
Hello list, I have a question. Take a look to the next models.

class MyDoc(models.Model):
code = models.BigIntegerField()

class Myline(models.mode):
   fk_myDoc = models.ForeignKey(MyDoc)
---

In my view I do something like

myPaginator = Paginator(MyDoc.objects.filter(codigo=1), 10)
myDocs = myPaginator.page(page_number)

This return all the Docs with a code=1, but I too want to return all
the objects with the type "MyLine" associated to the results of this
query.

I try to do something like

for i in range(len(myDocs.object_list))
myDocs.object_list[i].append(Myline.objects.filter(fk_myDoc=myDocs.object_list[i].id))
-
but don't work

I know that I can do 2 queries and return two list, one with the myDoc
list and other with the myLine list, but in that case in my template I
must to do something like

{% for myDoc im MyDocs.object.list %}
{% for myline in Mylines %}
   {%if myDoc.id == myline.fk_myDoc %}
   ..
   {% endif %}
{% endfor %}
{% endfor %}

I don't want to do this, because I think a big "for" inside a big
"for" is innecessary.

Somebody have an idea??
Thanks for read, and sorry for my bad english.

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



Re: slightly complicated radio input question

2010-12-13 Thread yiftah
thanks Ilian, I used the RadioSelect widget to create a radio list.
but i want to create text/select elements between the radio elements
(as in my example above)
any ideas?

yiftah

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



Re: Bringing down a website

2010-12-13 Thread Paul Winkler
On Dec 13, 10:20 am, Shamail Tayyab  wrote:
> What could be the simplest way to do it without altering any of my
> current views or anything?

Write a view for /shutdown which sets some global flag eg. in the
database,
then write some middleware to do the rest:
http://docs.djangoproject.com/en/dev/topics/http/middleware/

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



ForeignKey search

2010-12-13 Thread Michele JD Granocchia
(django 1.2)
Hi, i need to do the following:

Class 1, with a field called "field1" (CharField)
Class 2, with a field called "fieldwfk" (ForeignKey)

User enters a text and submits, which goes into "searchtext"

--- searchtext = request.GET.get('text')

Now i want to get all Class2 objects WHERE fieldwfk CONTAINS
searchtext.

With the following code:

---class1s =
Class1.objects.filter(field1__icontains=searchtext)
---cl2 =
Class2.objects.filter(fieldwfk__id=clienteric).order_by('-id')

or even with the following code:

---class1s =
Class1.objects.get(field1__icontains=searchtext)
---cl2 =
Class2.objects.filter(fieldwfk__id=class1s.id).order_by('-id')

I get what i want, but...
only if class1s matches only 1 record...
otherwise i get

--- Caught OperationalError while rendering: (1242, 'Subquery returns
more than 1 row')

in the first case
and

--- get() returned more than one Clienti -- it returned 3! Lookup
parameters were {'nomecliente__icontains': u'ca'}

in the second.

Plz help me... T_T

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



Re: Bringing down a website

2010-12-13 Thread Venkatraman S
# For preserving the data, use S3?
# Why not handle the 'bad' case in the test cases themselves?
# Arent you running the test cases on the box itself? or is it a different
entity? (I am not sure how this works on amazon though)

-V-
http://blizzardzblogs.blogspot.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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Bringing down a website

2010-12-13 Thread Shamail Tayyab
Hi,

   I am running a website which is currently running in its test
phase, it is a site which consumes too much bandwidth when running. We
are running the site on Amazon EC2 and paying bandwidth cost.

At times, I need to preserve over usage of data by bringing down the
website while our test cases go bad.

I am planning to write a handler like /shutdown which will ask me a
password and once down, all the pages will just return an HTTP 503.

What could be the simplest way to do it without altering any of my
current views or anything?

Thanks and 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Question on passing user to model objects

2010-12-13 Thread Daniel Roseman
On Monday, December 13, 2010 11:20:21 AM UTC, Scoox wrote:Hi Daniel,
thanks for your answer. Sorry, cmp should be c. I tried to only give
the import parts to make it more readable, but I made a mistake there.
The model code is pretty standard, except for one function:

isEditable=0
login=0
def editable(self):
if self.login==0: return False
else:
if self.isEditable!=0: return self.isEditable
if self==self.login.get_profile():
self.isEditable=True
for o in self.offer_set.all(): o.editable=True
return True
else:
self.isEditable=False
return False

(I added the isEditable attribute to cache if the object is editable,
since I wasn't sure if get_profile() is lazy loaded or sends a request
to the db with each iteration)

>> But the issue is likely to be that each call to foo_set.all()
creates a
>> brand new queryset fetched straight from the database. So doing
>> something on the result of calling .all() in the view is irrelevant
>> when you call .all again in the template.

That's probably right. But from what I understood, all() is a lazy
loader, so when Django loaded the objects once out of the db, it
should not do that again when the same object is called in a template.
Or did I understand that wrong?



That's not quite right. Calling .all() on a queryset is indeed lazy,
which means that it doesn't call the database until it's evaluated or
iterated. Subsequent iterations *on the same queryset object* do not
hit the database again.


However, calling foo.bar_set multiple times does *not* get the same
queryset each time. So, each one is a separate query, and changing
attributes on the instances returned by one iteration does not have any
effect on those returned by a second. I discuss this a little in a blog
entry here:
http://blog.roseman.org.uk/2010/01/11/django-patterns-part-2-efficient-reverse-lookups/



>> The best way to do this is probably to keep the queryset in a
variable
>> and send it explicitly to the template, then iterate through that
Yes that sounds possible. Just wondering if there is a cleaner way to
do it - the ideal way would of course every object having access to
the user in some way, but that seems impossible.



Does this necessarily need to be a model method? Why not a custom
template tag or filter, that you can pass the request.user object to?
--
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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



newbie question: Error while using tddspry module

2010-12-13 Thread girish shabadimath
Hi all,

Im working on djnago 1.2
i need to write tests for django models, what actually do i need to test in
models?


and also i found this link from google -
http://playpauseandstop.github.com/tddspry/writing_tests.html#database-tests-with-databasetestcase

and
installed all the necessary modules given in the above link
(mock,nose,twill)

and then used the example given in this link:
http://playpauseandstop.github.com/tddspry/writing_tests.html#usage

now  got the error:
ImportError: cannot import name TestSMTPConnection

am i missing anything,?
-- 
Girish M S

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



Re: Closing or resetting long-running connections

2010-12-13 Thread David De La Harpe Golden
On 12/12/10 12:10, Craig Trader wrote:

> What I would like to be able to do is to have my background process
> close and/or reset its database connection, as often as necessary.
> 
> Thank you in advance for any assistance you can render.


Yeah, note that django normally actually closes the connection after
processing of each http request [1]

We use django-celery, and so we install a signal handler for the
"task_postrun" signal celery fires upon task completion to try to do
similar upon completion of that each celery task. [2]
(I never proved the super-long-running connections were really an issue
for us, it was a pre-emptive thing based on other people's problem
reports, but we haven't had any problems in the area since...)

Basically, you probably just need to pick an opportune moment to do
similar in your vaguely-celery-like-thingy - each time a processor has
completed a job from your queue, say, have it close the connection. You
could involve signal handling if you wanted to structure things that
way, or not.

[1]
http://code.djangoproject.com/browser/django/trunk/django/db/__init__.py#L85


[2]
from django.db import reset_queries, close_connection
from celery.signals import task_prerun, task_postrun

task_prerun.connect(reset_queries, dispatch_uid=__name__)
task_postrun.connect(close_connection, dispatch_uid=__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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Using the Django Admin to change a password.

2010-12-13 Thread derek
I've been getting the same error.

There are a number of tickets that have been posted about this, most
of which were closed, the reason been given that they are duplicates
of:
http://code.djangoproject.com/ticket/3011
which has been open for four (4!) years.

http://code.djangoproject.com/ticket/9656
also purports to deal with this and gives some suggested code which
may work.

I'd really welcome an authoritative, working solution for this.

On Nov 20, 12:54 pm, Martin Melin  wrote:
> On Sat, Nov 20, 2010 at 10:44 AM, James Hancock  wrote:
> > I have a strange problem and don't really know where to start looking to fix
> > it. Can someone point me in the right direction to figure this one out.
>
> > In the Admin interface when I try to use the  "change password form" on any
> > of my users it gives me a
>
> > "Page not found (404)
> > Request Method:    GET
> > Request URL:   http://goeigo.org/admin/auth/user/21/password/
> > user object with primary key u'21/password' does not exist.
> > You're seeing this error because you have DEBUG = True in your Django
> > settings file. Change that to False, and Django will display a standard 404
> > page.
> > "
> > error..
>
> > I can change the passwords from the terminal and create users and stuff, but
> > the admin page doesn't seem to work.
>
> > Any hints?
>
> I assume that the rest of the admin is working?
>
> What version of Django are you using?
>
> Have you done anything out of the ordinary in urls.py?
>
> The problem seems to be that there is no URL pattern for the password
> change form, which means the user edit URL pattern will match instead,
> or that the pattern for password change comes after a broader pattern.
>
> Regards,
> Martin Melin
>
>
>
> > Cheers,
> > James Hancock
>
> > P.S. I love django

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



Re: Question on passing user to model objects

2010-12-13 Thread bruno desthuilliers
On 13 déc, 12:20, Scoox  wrote:
> Hi Daniel,
> thanks for your answer. Sorry, cmp should be c. I tried to only give
> the import parts to make it more readable, but I made a mistake there.
> The model code is pretty standard, except for one function:
>
>     isEditable=0
>     login=0

Assuming these two previous lines are at the top-level of you class
statement, both attributes will be class-attributes (that is "shared
by all instances"). I don't think this is what you want.

>     def editable(self):
>         if self.login==0: return False
>         else:
>             if self.isEditable!=0: return self.isEditable
>             if self==self.login.get_profile():

Are you sure you want to compare the current whatever instance with a
profile ???

>                 self.isEditable=True
>                 for o in self.offer_set.all(): o.editable=True

Such a side-effect is really really bad practice (and, in this case,
mostly useless).

>                 return True
>             else:
>                 self.isEditable=False
>                 return False


Code depending on the request.user should either takes an user as
param or live elsewhere.

> (I added the isEditable attribute to cache if the object is editable,
> since I wasn't sure if get_profile() is lazy loaded or sends a request
> to the db with each iteration)

When you aren't sure, check, don't wildguess.

> That's probably right. But from what I understood, all() is a lazy
> loader, so when Django loaded the objects once out of the db, it
> should not do that again when the same object is called in a template.
> Or did I understand that wrong?

You did. What "lazy" means here is that no request is issued until you
start to iterate over the queryset or subscript it.

> Yes that sounds possible. Just wondering if there is a cleaner way to
> do it - the ideal way would of course every object having access to
> the user in some way, but that seems impossible.

Indeed. How would your code work in another environnment (command line
tool for example) else ?

wrt/ "a cleaner way to do it", your business rules are not clear
enough to come with a sensible answer.

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



Re: default_if_none as settings (??)

2010-12-13 Thread PyMan
Oohh yes! That is what I was looking for. Still thanks!
As you said it's not working exactly how I use to rememeber...but it's
ok! :)

On 13 Dic, 14:15, bruno desthuilliers 
wrote:
> On 13 déc, 10:00, PyMan  wrote:
>
> > Maybe I'm wrong but I remember about a setting whose I don't remember
> > the name...acting like a default for default_if_none where
> > default_if_none was not used.
>
> > Example:
> > {{ value }}  <-- I forgot about using the "default_if_none" filter
>
> You're possibly thinking of TEMPLATE_STRING_IF_INVALID:
>
> http://docs.djangoproject.com/en/1.2/ref/settings/#template-string-if...
>
> but IIRC it won't work like this:
>
> > If the setting I'm talking about is defined then its value is used
> > instead of "None" as string, if value is None.

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



Re: default_if_none as settings (??)

2010-12-13 Thread bruno desthuilliers
On 13 déc, 13:15, Brad Reardon  wrote:
> If I understand correctly, then the solution would be to do something of
> this sort: (pardon the formatting)
>
> if value:
>     {{value}}
> else:
>     {{default_value}}


You may want to read about the builtin "default" and "default_if_none"
template filters ;)

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



Re: default_if_none as settings (??)

2010-12-13 Thread bruno desthuilliers
On 13 déc, 10:00, PyMan  wrote:
> Maybe I'm wrong but I remember about a setting whose I don't remember
> the name...acting like a default for default_if_none where
> default_if_none was not used.
>
> Example:
> {{ value }}  <-- I forgot about using the "default_if_none" filter

You're possibly thinking of TEMPLATE_STRING_IF_INVALID:

http://docs.djangoproject.com/en/1.2/ref/settings/#template-string-if-invalid

but IIRC it won't work like this:

> If the setting I'm talking about is defined then its value is used
> instead of "None" as string, if value is None.
>

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



Re: default_if_none as settings (??)

2010-12-13 Thread Brad Reardon
If I understand correctly, then the solution would be to do something of
this sort: (pardon the formatting)

if value:
{{value}}
else:
{{default_value}}

Something of that sort *should* work, although I am not entirely sure.

On Mon, Dec 13, 2010 at 4:00 AM, PyMan  wrote:

> Maybe I'm wrong but I remember about a setting whose I don't remember
> the name...acting like a default for default_if_none where
> default_if_none was not used.
>
> Example:
> {{ value }}  <-- I forgot about using the "default_if_none" filter
>
> If the setting I'm talking about is defined then its value is used
> instead of "None" as string, if value is None.
>
> I haven't found any information about that setting in the current
> documentation. If I really used that setting in the past, it was in
> the 0.95/0.96 version.
>
> Thank you for your help.
>
> P.S. If the setting doesn't exist, how can I achive the same result
> without using "default_if_none" everywhere?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



ANN: django-admin-tools 0.4.0 released

2010-12-13 Thread David Jean Louis

Hello,

I'm happy to announce the availability of the version 0.4.0 of 
django-admin-tools.


Django-admin-tools is a collection of extensions/tools for the default 
django administration interface, it includes:

  * a full featured and customizable dashboard,
  * a customizable menu bar,
  * tools to make admin theming easier.

Many bugs have been fixed, and new cool features were added in this 
version, see:

http://pypi.python.org/pypi/django-admin-tools/

Django-admin-tools is generously documented, you can browse the 
documentation online here:

http://packages.python.org/django-admin-tools/

A good start is to read the quickstart guide:
http://packages.python.org/django-admin-tools/0.4.0/quickstart.html

The project wiki (including screenshots), code and bugtracker are hosted 
on Bitbucket:

http://bitbucket.org/izi/django-admin-tools/

Many thanks to all the people who contributed to this release !

Regards,

--
David

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



Re: Display related field in queryset

2010-12-13 Thread Marcos Moyano
You can use field lookups:
http://docs.djangoproject.com/en/dev/topics/db/queries/#field-lookups-intro
ie: Travels.objects.values('date', 'destination__name')

Rgds,
Marcos

On Mon, Dec 13, 2010 at 6:51 AM, nsbk  wrote:

> Hello,
>
> I'm using http://code.google.com/p/django-jqgrid/ to display grids
> into a Django application. Since I'm pretty new to Django I don't know
> how to tell Django to retrurn the value of the related field instead
> of the id of the related field. What I do now is: travels =
> Travel.objects.values('date','destination'), but that returns the date
> of the travel and the id of the destination, FK to Destination model/
> table. How should I query Django so it returns the description of the
> destination instead of its id?
>
> Thanks in advance.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


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

Jamie Zawinski, in comp.emacs.xemacs

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



Re: Question on passing user to model objects

2010-12-13 Thread Scoox
Hi Daniel,
thanks for your answer. Sorry, cmp should be c. I tried to only give
the import parts to make it more readable, but I made a mistake there.
The model code is pretty standard, except for one function:

isEditable=0
login=0
def editable(self):
if self.login==0: return False
else:
if self.isEditable!=0: return self.isEditable
if self==self.login.get_profile():
self.isEditable=True
for o in self.offer_set.all(): o.editable=True
return True
else:
self.isEditable=False
return False

(I added the isEditable attribute to cache if the object is editable,
since I wasn't sure if get_profile() is lazy loaded or sends a request
to the db with each iteration)

>> But the issue is likely to be that each call to foo_set.all() creates a
>> brand new queryset fetched straight from the database. So doing
>> something on the result of calling .all() in the view is irrelevant
>> when you call .all again in the template.

That's probably right. But from what I understood, all() is a lazy
loader, so when Django loaded the objects once out of the db, it
should not do that again when the same object is called in a template.
Or did I understand that wrong?

>> The best way to do this is probably to keep the queryset in a variable
>> and send it explicitly to the template, then iterate through that
Yes that sounds possible. Just wondering if there is a cleaner way to
do it - the ideal way would of course every object having access to
the user in some way, but that seems impossible.



Kind Regards
Stephan

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



Dynamic Fields and Saving data per user

2010-12-13 Thread Dan
I am trying to make an app where each user will have like a mailing
list for which they should be-able to create custom fields for any
data they may want to hold and be able to save multiple rows of that
data.

I was thinking to use a model to hold the fields definitions and a key
value system to hold the data, something like this:

class Maillist(models.Model):
user = models.ForeignKey(User)


class Subscriber(models.Model):
email = models.EmailField()
list = models.ForeignKey(List)

class ListField(models.Model):
list = models.ForeignKey(Maillist)
field_type = models.IntegerField(choices=FIELD_TYPE_CHOICES)
label = models.CharField(_('Label'), max_length=100)

class SubscriberData(models.Model):
subscriber= models.ForeignKey(Subscriber, db_index=True)
key   = models.ForeignKey(ListField, db_index=True)
value = models.CharField(max_length=240, db_index=True)

Would this even work properly? Is there some better way to do it, what
about dynamically creating a model and its fields for each MailList?

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



Re: Question on passing user to model objects

2010-12-13 Thread Daniel Roseman
On Monday, December 13, 2010 10:22:32 AM UTC, Scoox wrote:Hi guys,
I have a (probably easy) question.

I need to pass the logged in user to my objects.

I have the objects company and offer.

I tried the following on the project's index / start view:

c = Company.objects.all()
cmp.login=request.user
for j in cmp.offer_set.all():
j.company.login=request.user
return render_to_response('show/startseite.html', {'company':
c},context_instance=RequestContext(request))

This works fine for the company objects. However, it does *not* for
the offer objects.

For whatever reason, even though it should be available, the offer's
user attribute is 0 (it's initial value).

The template is like this (shortened to cover only import points):

{% if company.editable %}(... user has edit rights - this works){%endif
%}

{% if company.offer_set.all %}
{% for item in company.offer_set.all %}
{% if journey.editable %} *** does not work ***

Strange enough, when I display the vars:
C: {{company.editable}} / OC: {{offer.company.editable}} / O:
{{offer.editable}}

I get
C: true / OC: false / O: false


So for whatever reason company does not seem to be the same as
offer.company, although it is in the same loop.



How could I solve this problem? Is there a suggested way to pass the
logged in user to all objects?



Kind Regards and thanks
Stephan



It's a bit hard to see what's going on, as you haven't provided your
model definitions and your code seems to be incomplete (what is cmp?)


But the issue is likely to be that each call to foo_set.all() creates a
brand new queryset fetched straight from the database. So doing
something on the result of calling .all() in the view is irrelevant
when you call .all again in the template.

The best way to do this is probably to keep the queryset in a variable
and send it explicitly to the template, then iterate through that:


offers = cmp.offer_set.all()
for j in offers:
 whatever ...
return render_to_response('show/startseite.html',
{'company': c, 'offers': offers},
context_instance=RequestContext(request))



and in the template:
{% for item in offers %}



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



Re: Rendering a field value in a custom way

2010-12-13 Thread Scoox
Hi Wayne,
thanks for your answer.

I now created a function that applies the render functions dynamically
to the object. So get_* is automagically created.

You are right about the downsides of this approach. However my
designer really does not like filters, so I have to stick to the
approach.


Kind Regards
Scoox

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



Question on passing user to model objects

2010-12-13 Thread Scoox
Hi guys,
I have a (probably easy) question.

I need to pass the logged in user to my objects.

I have the objects company and offer.

I tried the following on the project's index / start view:

c = Company.objects.all()
cmp.login=request.user
for j in cmp.offer_set.all():
j.company.login=request.user
   return render_to_response('show/startseite.html', {'company':
c},context_instance=RequestContext(request))

This works fine for the company objects. However, it does *not* for
the offer objects.

For whatever reason, even though it should be available, the offer's
user attribute is 0 (it's initial value).

The template is like this (shortened to cover only import points):

{% if company.editable %}(... user has edit rights - this works){%endif
%}

{% if company.offer_set.all %}
{% for item in company.offer_set.all %}
{% if journey.editable %} *** does not work ***

Strange enough, when I display the vars:
C: {{company.editable}} / OC: {{offer.company.editable}} / O:
{{offer.editable}}

I get
C: true / OC: false / O: false


So for whatever reason company does not seem to be the same as
offer.company, although it is in the same loop.



How could I solve this problem? Is there a suggested way to pass the
logged in user to all objects?



Kind Regards and thanks
Stephan

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



Display related field in queryset

2010-12-13 Thread nsbk
Hello,

I'm using http://code.google.com/p/django-jqgrid/ to display grids
into a Django application. Since I'm pretty new to Django I don't know
how to tell Django to retrurn the value of the related field instead
of the id of the related field. What I do now is: travels =
Travel.objects.values('date','destination'), but that returns the date
of the travel and the id of the destination, FK to Destination model/
table. How should I query Django so it returns the description of the
destination instead of its id?

Thanks in advance.

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



default_if_none as settings (??)

2010-12-13 Thread PyMan
Maybe I'm wrong but I remember about a setting whose I don't remember
the name...acting like a default for default_if_none where
default_if_none was not used.

Example:
{{ value }}  <-- I forgot about using the "default_if_none" filter

If the setting I'm talking about is defined then its value is used
instead of "None" as string, if value is None.

I haven't found any information about that setting in the current
documentation. If I really used that setting in the past, it was in
the 0.95/0.96 version.

Thank you for your help.

P.S. If the setting doesn't exist, how can I achive the same result
without using "default_if_none" everywhere?

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