Re: Static images for use in admin widget

2011-09-06 Thread Tomas Neme
> Inside the widget's render() function, I have a formatted string that
> contains embedded JS, and within that string I have a JS function that
> looks like:
>
> function showCrossHair(divId) {
>...
>div.innerHTML = '';
>...
> };

this looks awful to me. Can't you stick that into a .js file and include
that?

With that over, you can use djangodocs-Form Widget
Media
and
you can define a js-script somewhere inside your app/static/js/ directory. I
think hardcoding the 'app/' directory is the usual way to do this, you
should be the one naming your /static/app/ directory anyways, and you should
be doing your imports with absolute paths, but in case you still don't want
to, you can do something like

from django.conf import settings
import os
settings._DIR = os.path.dirname(__file__)

inside your app's root __init__.py file, and then do

from django.conf import settings
...
...
class MyWidget:
  class Media:
 js = ('%s/myfile.js'%settings._DIR)


I think

I'm pulling this up pretty straight out of my.. the blue, and it's really
too late, but I think this or something along this lines would work


--
"The whole of Japan is pure invention. There is no such country, there are
no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

-- 
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: Pagination of more than one field

2011-09-06 Thread OC
I am familiar with js but not with ajax
I thought that django supports these kind of matters ... isnt it
trivial?

Attached the code
Please advise

{% for movie in movies.object_list %#}

   {{movie.name}} 
  

{% endfor %}



{% if movies.has_previous %}

{% else %}

{% endif %}


{% for page_number in
movies.paginator.page_range %}
{% if page_number == movies.number %}
{{ movies.number }}
{% else %}
{{ page_number }}
{% endif %}
{% endfor %}

  
{% if movies.has_next %}

{% else %}

{% endif %}



{% for actor in actors.object_list %}
{% load parseval %}
{% autoescape off %}


{{ actor.pt|upper }}


{% endautoescape %}
{% empty %}
{% endfor %}
 

{% if actors.has_previous %}

{% else %}


{% for page_number in
actors.paginator.page_range %}
{% if page_number == actors.number %}
{{ actors.number }}
{% else %}
{{ page_number }}
{% endif %}
{% endfor %}

{% if actors.has_next %}

{% else %}

{% endif %}



On 6 ספטמבר, 17:41, Yaşar Arabacı  wrote:
> I think your question can be solved with javascript and ajax, rather than
> with django. How is your knowledge in that area?
>
> 2011/9/6 OC 
>
>
>
>
>
> > Hi,
>
> > I am new to django and I have a pagination question:
> > In my web page I need to display 2 query results of two different
> > tables
> > Each result is displayed in a different div in the same page.
>
> > How can I implement "multiple" pagination meaning that each result is
> > displayed in its own panel and has its own previous and next buttons
> > but doesn't affect the other's query result?
>
> > For instance - I have a panel of movies, display 10 each time, and
> > have a prev and next buttons dedicated to the movies only
> > Plus
> > In the same page, I have a panel of actors, display 10 each time, and
> > have a prev and next buttons dedicated to the actors only
>
> > My current (wrong) implementation is
> > use pagination for the both of them but when pressing the next/
> > previous button of one - it affects (as expected) the display of the
> > other one because the entire page has changed.
>
> > Thanks in advance,
> > Osnat
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --http://yasar.serveblog.net/-הסתר טקסט מצוטט-
>
> -הראה טקסט מצוטט-

-- 
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: Initial data for ManyToMany field

2011-09-06 Thread Tomas Neme
> Look into formsets. It's what the admin inlines use.

that is

class TypeMedicalForm(forms.ModelForm):
 class Meta:
model = TypeMedical
TypeMedicalFormSet=formset_factory(TypeMedicalForm)


take a look at the django docs for more details

--
"The whole of Japan is pure invention. There is no such country, there are
no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

-- 
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: Initial data for ManyToMany field

2011-09-06 Thread Tomas Neme
Look into formsets. It's what the admin inlines use.

On Tue, Sep 6, 2011 at 5:40 PM, Nan  wrote:

>
> Because SymptomeForm is a ModelForm, it will initialize its "parent"
> field as a ModelMultipleChoiceField, which I believe must be
> initialized with a queryset instead of a list.
>
> On Sep 6, 4:30 pm, Thomas49  wrote:
> > Hello,
> >
> > I have two models, and the second contains a ManyToMany relationship:
> >
> > class TypeMedical(models.Model):
> >...
> >
> > class Symptome(TypeMedical):
> > ...
> > parent =
> > models.ManyToManyField(TypeMedical,related_name='Parent',blank=True)
> > ...
> >
> > Then, I use a ModelForm in order to save data.
> >
> > class SymptomeForm(ModelForm):
> > class Meta:
> > model = Symptome
> >
> > When I create a form, sometimes I want to select a field in "parent".
> > How can I do that? I tried many things but nothing works. Ex:
> > sform = SymptomeForm(initial={'parent':["Acupuncture",]})
> >
> > I hope someone can help! Thanks,
> >
> > Thomas.
>
> --
> 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.
>
>


-- 
"The whole of Japan is pure invention. There is no such country, there are
no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

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



Static images for use in admin widget

2011-09-06 Thread Micky Hulse
Hello,

Within an admin field widget that I am developing, I need to access a
static image from my app.

For example, I have a Google map and I would like to access
"crosshair.gif" from the apps' static folder (er, the collectstatic
folder).

Inside the widget's render() function, I have a formatted string that
contains embedded JS, and within that string I have a JS function that
looks like:

function showCrossHair(divId) {
...
div.innerHTML = '';
...
};

Just wondering what the best way to generically access my app's media is?

Currently, my app has static files collected to this location:

site.com/static/app/...

Just curious of the best way to handle linking of images within
widgets whilst keeping things modular?

I was thinking that I could import STATIC_URL from settings and then
do something like this:

div.innerHTML = '';

... where "%(static)s" is a reference to my STATIC_URL constant.

I don't really like the above solution because "app" is hard-coded
into the path.

Another solution might be to have a constant at the top of the widget
file that contains the path to a crosshair image:

CROSSHAIR_FROM_STATIC = 'app/crosshair.gif'

But that seems kinda funky too.

Am I making any sense here? :D

Any tips would be greatly appreciated.

Thanks!

Cheers,
Micky

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



Re: How to group models month by month.

2011-09-06 Thread Mengu
this is overkill. the query you actually need is this (there even can
be a better way):

SELECT DATE_FORMAT(pub_date, "%Y %M") as pub_date, COUNT(*) as count
FROM app_posts
GROUP BY pub_date
ORDER BY count DESC

i have no idea how to pull this query by the Django ORM but you can
run this as a raw query like this:

Post.objects.raw("SELECT DATE_FORMAT(pub_date, "%Y %M") as pub_date,
COUNT(*) as count FROM app_posts GROUP BY pub_date ORDER BY count
DESC")

kolay gelsin.


On Sep 6, 5:30 pm, Yaşar Arabacı  wrote:
> I already read that, but I can figure out it is something to do with my
> question, bu can't figure out what exactly should I do with aggreates. I
> ended up doing something like this:
>     query_set = Post.objects.all()
>     years = query_set.dates("pub_date","year")
>     date_hierarchy = {}
>     for year in years:
>         date_hierarchy[year] = {}
>         months =
> query_set.filter(pub_date__year=year.year).dates("pub_date","month")
>         for month in months:
>             date_hierarchy[year][month] =
> query_set.filter(pub_date__year=month.year,pub_date__month=month.month).count()
>
> Then in template:
>
> {% for year, month_dict in date_hierarchy.items %}
> {% for month,post_count in month_dict.items %}
> {{ month|date:"Y
> E" }} [{{ post_count }}]
> {% endfor %}
> {% endfor %}
>
> 2011/9/6 Andre Terra 
>
>
>
>
>
>
>
>
>
> >http://django.me/aggregation
>
> > Cheers,
> > AT
>
> > 2011/9/6 Yaşar Arabacı 
>
> >> I have a model with datetime field. I want to get a table with three
> >> columns as, year, month and number of items in time span. And I also want 
> >> to
> >> order them from newest to oldest. What I want to get is something like 
> >> this:
>
> >> 2011 August 4
>
> >> 2011 March 7
>
> >>  How do you suggest I should do that?
>
> >> I am trying to add post archives to my front page in my blog. Here is link
> >> to same question on StackOverflow:
> >>http://stackoverflow.com/q/7320662/886669
> >>  --
> >>http://yasar.serveblog.net/
>
> >>  --
> >> 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.
>
> --http://yasar.serveblog.net/

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



multiple filters on the same (reversed) foreignkey leads to multiple join

2011-09-06 Thread dvd
A clean project/app in django 1.3 with just two models

from django.db import models

class Base(models.Model):
pass

class Child(models.Model):
base = models.ForeignKey(Base)
flag1 = models.BooleanField()
flag2 = models.BooleanField()

A Queryset with a single use of `.filter` works as expected:
>>> qs = Base.objects.filter(child__flag1=True)
>>> print qs.query
SELECT "t0_base"."id"
FROM "t0_base" INNER JOIN "t0_child"
ON ("t0_base"."id" = "t0_child"."base_id")
WHERE "t0_child"."flag1" = True

but if I start to add additional filters...
>>> qs = qs.filter(child__flag2=True)
>>> print qs.query
SELECT "t0_base"."id"
FROM "t0_base" INNER JOIN "t0_child"
ON ("t0_base"."id" = "t0_child"."base_id")
INNER JOIN "t0_child" T3
ON ("t0_base"."id" = T3."base_id")
WHERE ("t0_child"."flag1" = True  AND T3."flag2" = True )

>>> qs = qs.filter(child__flag1=False)
>>> print qs.query
SELECT "t0_base"."id"
FROM "t0_base" INNER JOIN "t0_child"
ON ("t0_base"."id" = "t0_child"."base_id")
INNER JOIN "t0_child" T3
 ON ("t0_base"."id" = T3."base_id")
INNER JOIN "t0_child" T4
 ON ("t0_base"."id" = T4."base_id")
WHERE ("t0_child"."flag1" = True  AND T3."flag2" = True  AND
T4."flag1" = False )

I don't think that this is the expected behavior, should I open a new
bug?

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-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: Initial data for ManyToMany field

2011-09-06 Thread Nan

Because SymptomeForm is a ModelForm, it will initialize its "parent"
field as a ModelMultipleChoiceField, which I believe must be
initialized with a queryset instead of a list.

On Sep 6, 4:30 pm, Thomas49  wrote:
> Hello,
>
> I have two models, and the second contains a ManyToMany relationship:
>
> class TypeMedical(models.Model):
>    ...
>
> class Symptome(TypeMedical):
>     ...
>     parent =
> models.ManyToManyField(TypeMedical,related_name='Parent',blank=True)
>     ...
>
> Then, I use a ModelForm in order to save data.
>
> class SymptomeForm(ModelForm):
>     class Meta:
>         model = Symptome
>
> When I create a form, sometimes I want to select a field in "parent".
> How can I do that? I tried many things but nothing works. Ex:
> sform = SymptomeForm(initial={'parent':["Acupuncture",]})
>
> I hope someone can help! Thanks,
>
> Thomas.

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



Initial data for ManyToMany field

2011-09-06 Thread Thomas49
Hello,

I have two models, and the second contains a ManyToMany relationship:

class TypeMedical(models.Model):
   ...

class Symptome(TypeMedical):
...
parent =
models.ManyToManyField(TypeMedical,related_name='Parent',blank=True)
...

Then, I use a ModelForm in order to save data.

class SymptomeForm(ModelForm):
class Meta:
model = Symptome

When I create a form, sometimes I want to select a field in "parent".
How can I do that? I tried many things but nothing works. Ex:
sform = SymptomeForm(initial={'parent':["Acupuncture",]})

I hope someone can help! Thanks,

Thomas.

-- 
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: Too many TCP connections

2011-09-06 Thread Cal Leeming [Simplicity Media Ltd]
Lmao, nice.

Glad you got the issue resolved!

On Tue, Sep 6, 2011 at 8:04 PM, shacker  wrote:

> Thanks for all the responses on this. After watching the error logs on the
> production server I saw tons of infinite redirect loops on calls for
> admin_media:
>
> "GET /admin_media/js/jqu///404.shtml/ HTTP/1.1" 302 -  ...
>
> This wasn't immediately apparent since the admin *seemed* to look and work
> properly. But that prompted me to poke around in the vhost definition for
> the admin_media alias, and sure enough, discovered we had two copies of
> Django installed in the virualenv - one in src and one in
> lib/pythton2.7/site-packages.  The vhost alias for admin_media was pointing
> to the wrong version, so some of the admin media worked while some did not.
>
> Basically, all of those bad requests were opening TCP connections that
> never got closed... which the firewall's CT_LIMIT feature noticed and
> blocked.
>
> To fix, I corrected the admin_media alias in the vhost and deleted the old
> Django installation.
>
> Thanks again.
>
> --
> 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/-/haoFj0tyzNIJ.
>
> 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: Too many TCP connections

2011-09-06 Thread shacker
Thanks for all the responses on this. After watching the error logs on the 
production server I saw tons of infinite redirect loops on calls for 
admin_media:

"GET /admin_media/js/jqu///404.shtml/ HTTP/1.1" 302 -  ...

This wasn't immediately apparent since the admin *seemed* to look and work 
properly. But that prompted me to poke around in the vhost definition for 
the admin_media alias, and sure enough, discovered we had two copies of 
Django installed in the virualenv - one in src and one in 
lib/pythton2.7/site-packages.  The vhost alias for admin_media was pointing 
to the wrong version, so some of the admin media worked while some did not. 

Basically, all of those bad requests were opening TCP connections that never 
got closed... which the firewall's CT_LIMIT feature noticed and blocked. 

To fix, I corrected the admin_media alias in the vhost and deleted the old 
Django installation.

Thanks again.

-- 
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/-/haoFj0tyzNIJ.
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: Pagination of more than one field

2011-09-06 Thread Yaşar Arabacı
I think your question can be solved with javascript and ajax, rather than
with django. How is your knowledge in that area?

2011/9/6 OC 

> Hi,
>
> I am new to django and I have a pagination question:
> In my web page I need to display 2 query results of two different
> tables
> Each result is displayed in a different div in the same page.
>
> How can I implement "multiple" pagination meaning that each result is
> displayed in its own panel and has its own previous and next buttons
> but doesn't affect the other's query result?
>
> For instance - I have a panel of movies, display 10 each time, and
> have a prev and next buttons dedicated to the movies only
> Plus
> In the same page, I have a panel of actors, display 10 each time, and
> have a prev and next buttons dedicated to the actors only
>
> My current (wrong) implementation is
> use pagination for the both of them but when pressing the next/
> previous button of one - it affects (as expected) the display of the
> other one because the entire page has changed.
>
> Thanks in advance,
> Osnat
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
http://yasar.serveblog.net/

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



Session value persistence between views

2011-09-06 Thread alaric
Hi:
I am very new to Django but I am trying to authenticate using Django's
session framework.
Problem is: I need the raw password to ssh as that user to retrieve
data on another machine. I haven't gotten it to work however.

I have a login view that looks like:

def login(request):
request.session['blah']=request.POST['username']
request.session['blah2']=request.POST['password']



def view_data(request):
username=request.session['blah']
password=request.session['blah2']


I get KeyError with view_data. Am I missing something here? I thought
the session data you assign persists between views. I can verify that
the cookie is stored with the sessionid, which would indicate to me
that I've changed session data.

Thanks.

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



Pagination of more than one field

2011-09-06 Thread OC
Hi,

I am new to django and I have a pagination question:
In my web page I need to display 2 query results of two different
tables
Each result is displayed in a different div in the same page.

How can I implement "multiple" pagination meaning that each result is
displayed in its own panel and has its own previous and next buttons
but doesn't affect the other's query result?

For instance - I have a panel of movies, display 10 each time, and
have a prev and next buttons dedicated to the movies only
Plus
In the same page, I have a panel of actors, display 10 each time, and
have a prev and next buttons dedicated to the actors only

My current (wrong) implementation is
use pagination for the both of them but when pressing the next/
previous button of one - it affects (as expected) the display of the
other one because the entire page has changed.

Thanks in advance,
Osnat

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



Re: How to group models month by month.

2011-09-06 Thread Yaşar Arabacı
I already read that, but I can figure out it is something to do with my
question, bu can't figure out what exactly should I do with aggreates. I
ended up doing something like this:
query_set = Post.objects.all()
years = query_set.dates("pub_date","year")
date_hierarchy = {}
for year in years:
date_hierarchy[year] = {}
months =
query_set.filter(pub_date__year=year.year).dates("pub_date","month")
for month in months:
date_hierarchy[year][month] =
query_set.filter(pub_date__year=month.year,pub_date__month=month.month).count()

Then in template:

{% for year, month_dict in date_hierarchy.items %}
{% for month,post_count in month_dict.items %}
{{ month|date:"Y
E" }} [{{ post_count }}]
{% endfor %}
{% endfor %}

2011/9/6 Andre Terra 

> http://django.me/aggregation
>
>
> Cheers,
> AT
>
> 2011/9/6 Yaşar Arabacı 
>
>>
>> I have a model with datetime field. I want to get a table with three
>> columns as, year, month and number of items in time span. And I also want to
>> order them from newest to oldest. What I want to get is something like this:
>>
>> 2011 August 4
>>
>>
>> 2011 March 7
>>
>>
>>  How do you suggest I should do that?
>>
>> I am trying to add post archives to my front page in my blog. Here is link
>> to same question on StackOverflow:
>> http://stackoverflow.com/q/7320662/886669
>>  --
>> http://yasar.serveblog.net/
>>
>>  --
>> 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.
>



-- 
http://yasar.serveblog.net/

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



Re: How to group models month by month.

2011-09-06 Thread Andre Terra
http://django.me/aggregation


Cheers,
AT

2011/9/6 Yaşar Arabacı 

>
> I have a model with datetime field. I want to get a table with three
> columns as, year, month and number of items in time span. And I also want to
> order them from newest to oldest. What I want to get is something like this:
>
> 2011 August 4
>
> 2011 March 7
>
>  How do you suggest I should do that?
>
> I am trying to add post archives to my front page in my blog. Here is link
> to same question on StackOverflow:
> http://stackoverflow.com/q/7320662/886669
>  --
> http://yasar.serveblog.net/
>
>  --
> 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 to group models month by month.

2011-09-06 Thread Yaşar Arabacı
I have a model with datetime field. I want to get a table with three columns
as, year, month and number of items in time span. And I also want to order
them from newest to oldest. What I want to get is something like this:

2011 August 4
2011 March 7

How do you suggest I should do that?

I am trying to add post archives to my front page in my blog. Here is link
to same question on StackOverflow: http://stackoverflow.com/q/7320662/886669
-- 
http://yasar.serveblog.net/

-- 
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: forms.ChoiceField/forms.ModelChoiceField Needs a Lot of Love

2011-09-06 Thread Reinout van Rees

On 05-09-11 23:09, Terribyte wrote:

I don't know if anyone has said this outright, but I think that
ChoiceField and ModelChoiceField are just broken.

It seems that every time I want to do something with them I'm having
to write a custom init function get what I want done.

As a community I think we should be able to improve the "genericness"
of them in such a way that would allow smart filtering of model lists,
default settings, and a few other features that as an object they are
wonting for.

I know that this remark is far too generic and requires a great deal
more "fleshing out" but I wanted to throw that out there as I'm
banging my head -- once again -- on the desk trying to get django
forms to spit out a choice field that does what I want it to do and
wished to share my frustration.


I hope it helped :-)

From time to time someone says that a feature that's been a long time 
in Django is "just broken". Well, the common answer is that that's 
nonsense, precisely because it is in Django for a long time and lots of 
people are using it. So it cannot be broken. Perhaps sub-optimal, but 
not broken.


Just telling you the standard reaction I've seen :-)

I *guess* that choice fields is a pretty hard problem to solve correctly 
and probably impossible to solve generically. Perhaps a custom init 
function *is* the right way?


Anyway, could you give an example where you have to write a custom init? 
Mayhap there's an easy solution, mayhap it suggests improvements to the 
generic choicefield?



Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
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: Use primary key in filenames on FileFields

2011-09-06 Thread Stratos Moros
This wouldn't work. It will work for updates, but when a new Decision
object is created, "get_file_path" runs before the object is saved and
self.id will be None.

On Sep 5, 6:51 pm, Bingimar  wrote:
> try this
>
> def get_file_path(instance, filename):
>     path = 'your upload directory'
>     extension = filename.split('.')[-1].lower()
>     new_file_name = self.id
>
>     return '%(path)s/%(filename)s.%(extension)s' %
>                                                    {
>                                                        'path': path,
>                                                        'filename':
> new_file_name',
>                                                        'extension':
> extension
>                                                    }
>
> class Decision(m.Model):
>     ...
>     decision = m.FileField(upload_to=get_file_path)
>
> On Sep 5, 11:01 am, Stratos Moros  wrote:
>
>
>
> > I forgot to mention that i have imported models like this:
>
> > import django.db.models as m
>
> > This should explain the first two lines.
>
> > On Mon, Sep 5, 2011 at 12:28 PM, Stratos Moros  wrote:
> > > Hello,
>
> > > I have a model that includes a FileField. When the user uploads a file
> > > via the admin interface, I want the file to be saved as 'upload_to/
> > > primary_key/original_filename'. Since the object will not be saved in
> > > the database when the user uploads the file, it will not have a
> > > primary key at that point. This is my workaround:
>
> > > class Decision(m.Model):
> > >    ...
> > >    decision = m.FileField(upload_to='base_dir/')
> > >    ...
>
> > >    def save(self, *args, **kwargs):
> > >        """ custom save to use pk on filename """
> > >        #save once to get a pk
> > >        super(Decision, self).save(*args, **kwargs)
>
> > >        #get info about the file
> > >        uploaded = self.decision
> > >        old_path = self.decision.name
> > >        basedir, filename = os.path.split(old_path)
> > >        new_path = os.path.join(basedir, str(self.pk), filename)
>
> > >        #create the new file, delete the one django created
> > >        uploaded.storage.save(new_path, uploaded)
> > >        uploaded.storage.delete(old_path)
>
> > >        #assign new path and save again
> > >        self.decision = new_path
> > >        super(Decision, self).save(*args, **kwargs)
>
> > > This works, but seems to be a bit on the hacky side. Basically, I'm
> > > letting FileField upload the file to the 'upload_to' path and then
> > > move it to its correct path when the object has a primary key.
>
> > > I was wondering if there is a better way to do this. Are there any
> > > cases where my code wouldn't work?
>
> > > Thanks.

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



Re: Authorization workflow model

2011-09-06 Thread Julien Castets
Hi,

I faced to the same problem than you a few weeks ago, and I found this
: https://github.com/dominno/django-moderation#readme
It seems to be what you're searching.



On Tue, Sep 6, 2011 at 5:55 AM, Mike Dewhirst  wrote:
> On 6/09/2011 5:46am, Mario8k wrote:
>>
>> Hello,
>>
>> Does anyone knows some solution (reusable app, snippet or any idea) to
>> model an authorization workflow of data?
>>
>> That is... supose that a user have restricted some model field, ie,
>> cannot edit directly this field. And now supose that he could request
>> to change that field,  seeing the real content and editing it, and
>> then "save" model. Saving model, doesn't commit the transaction, until
>> another user (an administrator) authorize the change (the actual
>> commit).
>>
>> Any idea?
>
> I would consider keeping all the edits in the same record. Then you could
> have 'approved' and 'edited' as two versions of the field. For example, the
> lower-privileged user edits a copy of 'approved' in 'edited' and save() just
> saves it. When the admin eventually approves it, the 'edited' field gets
> copied to the real field.
>
> mike
>>
>> A trivial idea is to have another request model replicating the
>> structure (or only the restricted fields) of the original one. So, the
>> user who need to change the restricted fields completes this new
>> model.
>> For example:
>>
>>  class Foo(model.Models):
>>      name = models.CharField()
>>
>>  class FooRequest(model.Models):
>>     name = models.CharField()
>>
>> Then we need an action to copy and replace data to Foo from
>> FooRequest.
>>
>> The problem with this solution, is that i need it for a lot of models,
>> not just one.
>>
>> Thanks for your time,
>> Regards,
>>
>> Mario.
>>
>>
>>
>
> --
> 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.
>
>



-- 
Julien Castets
+33 (0)6.85.20.10.03

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



Re: Admin TabularInline Edit Parent Record?

2011-09-06 Thread Uros Trebec
I would like this very much, if someone has any ideas on how to
achieve it.

--
Uros

On Sep 6, 4:35 am, Lee  wrote:
> I use TabularInlines for Many-to-Many join tables, with the foreign
> keys appearing in select lists. The Admin interface automatically
> provides the stellar "Add-Another" icon (a plus sign) with the select
> list, to add a new parent record on the fly. It would be extremely
> useful to also have an edit icon (often a pencil) that would edit the
> related parent record. Any easy way to to do that?
>
> Thanks for any help or ideas.
>
> Lee

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



Re: How to use ModelForm for both new or existing data

2011-09-06 Thread Shawn Milochik
How about checking for the existence of course_id in the view? Then if
it's blank you just send request.POST and if not you grab the instance
in the view and pass it as the instance kwarg.

Alternately you could do the same in the __init__ of the modelform,
before you call the super __init__. It depends on which one will be
easier to understand and maintain for your app.

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