Upload file and primary key - double save

2012-05-02 Thread Leonardo Giordani
Hi all,

I'm developing a site where the object Project is referenced by zero or
more objects Image, say basically

 CODE 

class Projects(models.Model):
 pass

class Image(models.Model):
 project = models.ForeignKey(Project)

---

I would like to have all images served as 001.jpeg, 002.jpeg and so on, and
I'd prefer to host them locally in a per-project subdirectory of my media
storage path.

I can implement a new save() to create a media subdirectory called with a
name containing the Project PK.

How can I move all images (previously saved in a directory specified in
Image's upload_to parameter) to the new directory?
Is the Project's save() the correct place to do this?

Thank you in advance

Leo

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



Re: Where is "base.html" that "templates/site_base.html" extends?

2011-09-09 Thread Leonardo Giordani
Hi Christos,

if you put

{% extends "somefile.html" %}

in your template, Django expects to find it in one of the directories
specified in your TEMPLATE_DIRS variable in settings.py.
They are considered in the order they are written, so the base.html you are
extending is the first you find in this sequence.

Hope this helps, feel free to reply

2011/9/9 Christos Jonathan Hayward 

> "site_base.html", directly under the templates folder, extends a
> "base.html".
>
> Where is the base.html? I see several under the project heirarchy
> somewhere, and I'd like to know which one of them site_base.html extends (if
> it does so), or else where I can go to edit site_base.html.
>
> --
> [image: Christos Jonathan Hayward] 
> Christos Jonathan Hayward, an Orthodox Christian author.
>
> Author Bio  • 
> Books
>  • *Email * • 
> Facebook
>  • Google Plus  • 
> LinkedIn
>  • Twitter  • 
> *Web
> * • What's New? 
> I invite you to visit my "theology, literature, and other creative works"
> site.
>
>  --
> 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.



Testing: create db from scratch not working

2011-09-22 Thread Leonardo Giordani
Hi all,

I developed a Django application (named "manouche") using south. Thus
I have some migrations which build my database.

I want to setup a testing environment where I want to begin with a
clean db, create it with syncdb, migrate my application, load current
fixtures and run tests.

My installed applications are

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.flatpages',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'accounts',
'south',
'manouche',
)

But if I clean up the db and run "./manage.py syncdb" I get the following

Traceback (most recent call last):
  File "./manage.py", line 14, in 
execute_manager(settings)
  File 
"/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py",
line 438, in execute_manager
utility.execute()
  File 
"/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py",
line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py",
line 191, in run_from_argv
self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py",
line 219, in execute
self.validate()
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py",
line 249, in validate
num_errors = get_validation_errors(s, app)
  File 
"/usr/local/lib/python2.6/dist-packages/django/core/management/validation.py",
line 36, in get_validation_errors
for (app_name, error) in get_app_errors().items():
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py",
line 146, in get_app_errors
self._populate()
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py",
line 61, in _populate
self.load_app(app_name, True)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py",
line 78, in load_app
models = import_module('.models', app_name)
  File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py",
line 35, in import_module
__import__(name)
  File "/users/gleo/Devel/stargate/manouche/models.py", line 14, in 
current_site = Site.objects.get_current()
  File "/usr/local/lib/python2.6/dist-packages/django/contrib/sites/models.py",
line 25, in get_current
current_site = self.get(pk=sid)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/manager.py",
line 132, in get
return self.get_query_set().get(*args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py",
line 344, in get
num = len(clone)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py",
line 82, in __len__
self._result_cache = list(self.iterator())
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py",
line 273, in iterator
for row in compiler.results_iter():
  File 
"/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py",
line 680, in results_iter
for rows in self.execute_sql(MULTI):
  File 
"/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py",
line 735, in execute_sql
cursor.execute(sql, params)
  File "/usr/local/lib/python2.6/dist-packages/django/db/backends/util.py",
line 34, in execute
return self.cursor.execute(sql, params)
  File 
"/usr/local/lib/python2.6/dist-packages/django/db/backends/mysql/base.py",
line 86, in execute
return self.cursor.execute(query, args)
  File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 166, in execute
self.errorhandler(self, exc, value)
  File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 35,
in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.DatabaseError: (1146, "Table
'stargate_devel.django_site' doesn't exist")

Where "stargate" is the name of my project.
If I remove my "manouche" application everything works fine. Then I
put in my application, run "./manage.pty migrate manouche" and be
happy.

However I do not understand why it is not working when all
applications are present in settings.py and how I can automatically
get a complete install, without having to manually remove my
application from the settings.

Any help appreciated, thank you

Leo

-- 
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: Testing: create db from scratch not working

2011-09-22 Thread Leonardo Giordani
Sure my application depends on the site app, I'm importing Site in my models.py.
But manouche is already at the bottom of the list, so this does not work.

2011/9/22 J. Cliff Dyer :
> Try putting manouche at the bottom of your installed apps list. It looks
> like it depends on the site app being installed, but when django loads the
> manouche.models file, it hasn't loaded sites yet.
> --
> Sent from my Android phone with K-9 Mail. Please excuse my brevity.
>
> Leonardo Giordani  wrote:
>>
>> Hi all,
>>
>> I developed a Django application (named "manouche") using south. Thus
>> I have some migrations which build my database.
>>
>> I want to setup a testing environment where I want to begin with a
>> clean db, create it with syncdb, migrate my application, load current
>> fixtures and run tests.
>>
>> My installed applications are
>>
>> INSTALLED_APPS = (
>> 'django.contrib.auth',
>> 'django.contrib.contenttypes',
>> 'django.contrib.sessions',
>> 'django.contrib.sites',
>> 'django.contrib.flatpages',
>> 'django.contrib.messages',
>> 'django.contrib.staticfiles',
>> 'django.contrib.admin',
>> 'accounts',
>> 'south',
>> 'manouche',
>> )
>>
>> But if I clean up the db and run "./manage.py syncdb" I get the following
>>
>> Traceback (most recent call last!
>>  ):
>>
>>  File "./manage.py", line 14, in 
>> execute_manager(settings)
>>   File
>> "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py",
>> line 438, in execute_manager
>> utility.execute()
>>   File
>> "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py",
>> line 379, in execute
>> self.fetch_command(subcommand).run_from_argv(self.argv)
>>   File
>> "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py",
>> line 191, in run_from_argv
>> self.execute(*args, **options.__dict__)
>>   File
>> "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py",
>> line 219, in execute
>> self.validate()
>>   File
>> "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py",
>> line 249, in validate
>> num_errors = get_validation_errors(!
>>  s,
>> app)
>>   File
>> "/usr/local/lib/python2.6/dist-packages/django/core/management/validation.py",
>> line 36, in get_validation_errors
>> for (app_name, error) in get_app_errors().items():
>>   File
>> "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py",
>> line 146, in get_app_errors
>> self._populate()
>>   File
>> "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py",
>> line 61, in _populate
>> self.load_app(app_name, True)
>>   File
>> "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py",
>> line 78, in load_app
>> models = import_module('.models', app_name)
>>   File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py",
>> line 35, in import_module
>> __import__(name)
>>   File
>> "/users/gleo/Devel/stargate/manouche/models.py", line 14, in 
>> current_site = Site.objects.get_current()
>>   File
>> "/usr/local/lib/python2.6/dist-packages/django/contrib/sites/models.py",
>> line 25, in get_current
>> current_site = self.get(pk=sid)
>>   File
>> "/usr/local/lib/python2.6/dist-packages/django/db/models/manager.py",
>> line 132, in get
>> return self.get_query_set().get(*args, **kwargs)
>>   File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py",
>> line 344, in get
>> num = len(clone)
>>   File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py",
>> line 82, in __len__
>> self._result_cache = list(self.iterator())
>>   File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py",
>> line 273, in iterator
>> for row in compiler.results_iter():
>>   File
>> "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compiler.py",
>> line 680, in results_iter
>> for rows in self.execute_sql(MULTI):
>>   File
>> "/usr/local/lib/python2.6/dist-packages/django/db/models/sql/compile

Re: Testing: create db from scratch not working

2011-09-22 Thread Leonardo Giordani
This is very strange for me: even flatpages depends on Site

/usr/local/lib/python2.6/dist-packages/django/contrib/flatpages/models.py:from
django.contrib.sites.models import Site

but there is no problem in listing both in INSTALLED_APPS and to
syncdb them togheter.

My application depends on Site the same way

manouche/models.py:from django.contrib.sites.models import Site

but I cannot syncdb it with other applications.

No one can help?

2011/9/22 Leonardo Giordani :
> Sure my application depends on the site app, I'm importing Site in my 
> models.py.
> But manouche is already at the bottom of the list, so this does not work.
>
> 2011/9/22 J. Cliff Dyer :
>> Try putting manouche at the bottom of your installed apps list. It looks
>> like it depends on the site app being installed, but when django loads the
>> manouche.models file, it hasn't loaded sites yet.
>> --
>> Sent from my Android phone with K-9 Mail. Please excuse my brevity.
>>
>> Leonardo Giordani  wrote:
>>>
>>> Hi all,
>>>
>>> I developed a Django application (named "manouche") using south. Thus
>>> I have some migrations which build my database.
>>>
>>> I want to setup a testing environment where I want to begin with a
>>> clean db, create it with syncdb, migrate my application, load current
>>> fixtures and run tests.
>>>
>>> My installed applications are
>>>
>>> INSTALLED_APPS = (
>>>     'django.contrib.auth',
>>>     'django.contrib.contenttypes',
>>>     'django.contrib.sessions',
>>>     'django.contrib.sites',
>>>     'django.contrib.flatpages',
>>>     'django.contrib.messages',
>>>     'django.contrib.staticfiles',
>>>     'django.contrib.admin',
>>>     'accounts',
>>>     'south',
>>>     'manouche',
>>> )
>>>
>>> But if I clean up the db and run "./manage.py syncdb" I get the following
>>>
>>> Traceback (most recent call last!
>>>  ):
>>>
>>>  File "./manage.py", line 14, in 
>>>     execute_manager(settings)
>>>   File
>>> "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py",
>>> line 438, in execute_manager
>>>     utility.execute()
>>>   File
>>> "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py",
>>> line 379, in execute
>>>     self.fetch_command(subcommand).run_from_argv(self.argv)
>>>   File
>>> "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py",
>>> line 191, in run_from_argv
>>>     self.execute(*args, **options.__dict__)
>>>   File
>>> "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py",
>>> line 219, in execute
>>>     self.validate()
>>>   File
>>> "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py",
>>> line 249, in validate
>>>     num_errors = get_validation_errors(!
>>>  s,
>>> app)
>>>   File
>>> "/usr/local/lib/python2.6/dist-packages/django/core/management/validation.py",
>>> line 36, in get_validation_errors
>>>     for (app_name, error) in get_app_errors().items():
>>>   File
>>> "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py",
>>> line 146, in get_app_errors
>>>     self._populate()
>>>   File
>>> "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py",
>>> line 61, in _populate
>>>     self.load_app(app_name, True)
>>>   File
>>> "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py",
>>> line 78, in load_app
>>>     models = import_module('.models', app_name)
>>>   File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py",
>>> line 35, in import_module
>>>     __import__(name)
>>>   File
>>> "/users/gleo/Devel/stargate/manouche/models.py", line 14, in 
>>>     current_site = Site.objects.get_current()
>>>   File
>>> "/usr/local/lib/python2.6/dist-packages/django/contrib/sites/models.py",
>>> line 25, in get_current
>>>     current_site = self.get(pk=sid)
>>>   File
>>> "/usr/local/lib/python2.6/dist-packages/django/db/models/manager.py",
>>> lin

Re: Testing: create db from scratch not working

2011-09-22 Thread Leonardo Giordani
Ok, solved.

The problem was the following declaration in my models.py

current_site = Site.objects.get_current()

which tries to read the current site at registration time, before
sites has been properly filled with values.
I just replaced every use of current_site with a call to get_current()
and everything works.

Leo


2011/9/22 Leonardo Giordani :
> This is very strange for me: even flatpages depends on Site
>
> /usr/local/lib/python2.6/dist-packages/django/contrib/flatpages/models.py:from
> django.contrib.sites.models import Site
>
> but there is no problem in listing both in INSTALLED_APPS and to
> syncdb them togheter.
>
> My application depends on Site the same way
>
> manouche/models.py:from django.contrib.sites.models import Site
>
> but I cannot syncdb it with other applications.
>
> No one can help?
>
> 2011/9/22 Leonardo Giordani :
>> Sure my application depends on the site app, I'm importing Site in my 
>> models.py.
>> But manouche is already at the bottom of the list, so this does not work.
>>
>> 2011/9/22 J. Cliff Dyer :
>>> Try putting manouche at the bottom of your installed apps list. It looks
>>> like it depends on the site app being installed, but when django loads the
>>> manouche.models file, it hasn't loaded sites yet.
>>> --
>>> Sent from my Android phone with K-9 Mail. Please excuse my brevity.
>>>
>>> Leonardo Giordani  wrote:
>>>>
>>>> Hi all,
>>>>
>>>> I developed a Django application (named "manouche") using south. Thus
>>>> I have some migrations which build my database.
>>>>
>>>> I want to setup a testing environment where I want to begin with a
>>>> clean db, create it with syncdb, migrate my application, load current
>>>> fixtures and run tests.
>>>>
>>>> My installed applications are
>>>>
>>>> INSTALLED_APPS = (
>>>>     'django.contrib.auth',
>>>>     'django.contrib.contenttypes',
>>>>     'django.contrib.sessions',
>>>>     'django.contrib.sites',
>>>>     'django.contrib.flatpages',
>>>>     'django.contrib.messages',
>>>>     'django.contrib.staticfiles',
>>>>     'django.contrib.admin',
>>>>     'accounts',
>>>>     'south',
>>>>     'manouche',
>>>> )
>>>>
>>>> But if I clean up the db and run "./manage.py syncdb" I get the following
>>>>
>>>> Traceback (most recent call last!
>>>>  ):
>>>>
>>>>  File "./manage.py", line 14, in 
>>>>     execute_manager(settings)
>>>>   File
>>>> "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py",
>>>> line 438, in execute_manager
>>>>     utility.execute()
>>>>   File
>>>> "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py",
>>>> line 379, in execute
>>>>     self.fetch_command(subcommand).run_from_argv(self.argv)
>>>>   File
>>>> "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py",
>>>> line 191, in run_from_argv
>>>>     self.execute(*args, **options.__dict__)
>>>>   File
>>>> "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py",
>>>> line 219, in execute
>>>>     self.validate()
>>>>   File
>>>> "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py",
>>>> line 249, in validate
>>>>     num_errors = get_validation_errors(!
>>>>  s,
>>>> app)
>>>>   File
>>>> "/usr/local/lib/python2.6/dist-packages/django/core/management/validation.py",
>>>> line 36, in get_validation_errors
>>>>     for (app_name, error) in get_app_errors().items():
>>>>   File
>>>> "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py",
>>>> line 146, in get_app_errors
>>>>     self._populate()
>>>>   File
>>>> "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py",
>>>> line 61, in _populate
>>>>     self.load_app(app_name, True)
>>>>   File
>>>> "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py",
>>>> lin

Forms with FileField - access file content

2011-10-20 Thread Leonardo Giordani
Hi all,

I'm trying to implement a an application where the user creates a new object
through a form. Up to here I'm fine.

This time though the object creation involves loading a file and choosing
some data from it (say choosing some lines, for examples).

So I'm a little stuck here. How can I let the user load the file and show
the file content in the form itself before submitting?

Or is this behaviour wrong for a Web application?

Any advice is appreciated, thank you in advance

Leo

-- 
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 with FileField - access file content

2011-10-20 Thread Leonardo Giordani
No, I think I didn't correctly explain the matter; say I have a Thing model
with a list of strings in it.

I want the user to be able to:

1. Access the Thing creation form
2. While editing the form loading a file and being presented with the full
content
3. Choosing some lines from that content
4. Submit the form

So I need to "modify" the view attaching fields which content comes from
what the user uploads.

2011/10/20 Venkatraman S 

>
> On Thu, Oct 20, 2011 at 1:32 PM, Leonardo Giordani <
> giordani.leona...@gmail.com> wrote:
>
>>
>> I'm trying to implement a an application where the user creates a new
>> object through a form. Up to here I'm fine.
>>
>> This time though the object creation involves loading a file and choosing
>> some data from it (say choosing some lines, for examples).
>>
>> So I'm a little stuck here. How can I let the user load the file and show
>> the file content in the form itself before submitting?
>>
>> Or is this behaviour wrong for a Web application?
>>
>
>
> Probably, you may want to show the contents of the file after the user
> uploads the file? So that the file's copy is present in the server.
> If you want to show the preview of the doc in the app, i would suggest
> generating a summary or clip a few lines when the model is saved, and store
> the summary in a different field, so that you can avoid run-time
> computations of the summary when the file is to be accessed.
>
> Did i get you right?
>
> -V
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
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 with FileField - access file content

2011-10-20 Thread Leonardo Giordani
Yes you are right, I was not thinking about security. :)

Thanks

2011/10/20 Tom Evans 

> On Thu, Oct 20, 2011 at 10:49 AM, Leonardo Giordani
>  wrote:
> > No, I think I didn't correctly explain the matter; say I have a Thing
> model
> > with a list of strings in it.
> >
> > I want the user to be able to:
> >
> > 1. Access the Thing creation form
> > 2. While editing the form loading a file and being presented with the
> full
> > content
> > 3. Choosing some lines from that content
> > 4. Submit the form
> >
> > So I need to "modify" the view attaching fields which content comes from
> > what the user uploads.
>
> You cannot do that. You can upload the file in the background after
> the user has selected the file, using AJAX. Once the file has been
> uploaded the server could return the contents as a form control, and
> allow the user to select the parts of it they wish. Gmail partially
> does this - once you have selected a file to attach, it uses AJAX to
> upload it in the background whilst you type your email.
>
> Fortunately, there is no way for a web developer to instruct a browser
> to open a file from disk and insert its contents into form controls.
> If you think about it, you will understand why.
>
> Cheers
>
> Tom
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Radio button with nested widget

2011-10-20 Thread Leonardo Giordani
Hi all,

I'm trying to implement the following form: a first ChoiceField with values
"mode 1", "mode 2" or "manual".

Depending on its value I need to show a FileUpload field (mode1 or mode2) or
some CharFields (mode3).

I'm trying to mimic a desktop GUI, where you can three radio button and each
can contain something: a file upload the first two, some text fields the
third.

Some advices?

Thank you

Leo

-- 
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: create object instance with ManyToManyField

2011-10-27 Thread Leonardo Giordani
Hi Jaroslav,

you have to do the following

n = Company(name=my_name, country=my_country, isin=my_isin)
n.save()
n.indices.add(my_indices)

See here 
https://docs.djangoproject.com/en/dev/topics/db/queries/#saving-foreignkey-and-manytomanyfield-fields

Bye

2011/10/27 Jaroslav Dobrek :
> Hello,
>
> how can I create an object instance with a ManyToManyField. Everything
> works fine via the admin interface. But I don't understand how to do
> it in Python.
>
> Example: I have this model:
>
> class Company(models.Model):
>
>    name = models.CharField(max_length=200, unique=True)
>    country = models.ForeignKey(Country)
>    isin = models.CharField(max_length=12, blank=True)
>    indices = models.ManyToManyField(Index, blank=True)
>
>    def the_indices(self):
>        ind = []
>        for index in self.indices.all():
>            ind.append(index.name)
>        return ', '.join(ind)
>    the_indices.short_description = u'Indices'
>
>    def __unicode__(self):
>        return self.name
>
> This will work:
>
> n = Company(name=my_name, country=my_country, isin=my_isin)
> n.save()
>
> This will not work:
>
> n = Company(name=my_name, country=my_country, isin=my_isin,
> indices=my_indices)
> n.save()
>
> Although I make sure that my_indices is a list of existing index
> objects.
>
> What do I have to do?
>
> Jaroslav
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Database management commands

2011-10-27 Thread Leonardo Giordani
This is a problem related to Innodb and MyISAM. Django uses this
latter, while probably your imported DB is an Innodb one.
Check here https://docs.djangoproject.com/en/dev/ref/databases/
Search Google for the matter too, you are not the only one experiencing it.

I would suggest getting rid of the new tables you created, switching
to InnoDB and migrating everything.

Try and let me know.

Leo

2011/10/27 Daniele Procida :
> I keep getting errors like this:
>
> _mysql_exceptions.OperationalError: (1005, "Can't create table 
> 'arkestra_medic_dev.#sql-51b_4a8' (errno: 150)")
>
> when running database management commands (syncdb, south migrate).
>
> Sometimes those commands work, sometimes they don't; it happens across a 
> variety of apps.
>
> I am working on a database that was exported from one system and has been 
> imported into a new one.
>
> Running Django 1.3.1. I'm pretty sure the issue is something to do with my 
> database/setup, rather than anything in the apps involved.
>
> Any suggestions greatly appreciated.
>
> Daniele
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Database management commands

2011-10-28 Thread Leonardo Giordani
You are right, thanks.

2011/10/28 Russell Keith-Magee :
> On Fri, Oct 28, 2011 at 12:49 AM, Leonardo Giordani
>  wrote:
>> This is a problem related to Innodb and MyISAM. Django uses this
>> latter,
>
> Incorrect. Django doesn't have any built in preference for InnoDB or
> MyISAM -- it uses the system default table type. On most systems,
> MyISAM is the default, but this isn't guaranteed or expected.
>
> Django supports both MyISAM and InnoDB table types, but the available
> feature set changes depending on the underlying table store.
>
> Yours,
> Russ Magee %-)
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
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: create object instance with ManyToManyField

2011-10-28 Thread Leonardo Giordani
The add() method of a ManyToMany field adds the indexes of the given
objects to the field.
If you add a list, each index in the list is added to the field.

In the admin interface, when you edit a Company object, you see a
convenient automagically-created
menu which lists all Index object in your application, and there you
can add or remove them.

But you can add Indexes with the snipped I gave you; if you pass as
"my_indices" some of the
available Indexes and then edit the object through the admin interface
you'll see the ones you added
as selected (in blue).

*Choices* in the admin interface are build through an automatic query;
Django sees that you use a m2m field
and populates it with TheTypeYouReference.objects.all() . But this is
a service of the forms in the admin interface.
Django objects have nothing to do with "choices", they simply know
that you are attaching the index of some
other object to the object you are creating.

Feel free to ask again if the matter is not clear.


2011/10/28 Jaroslav Dobrek :
> Hello Leonardo,
>
> thanks your your answer.
>
>> n = Company(name=my_name, country=my_country, isin=my_isin)
>> n.save()
>> n.indices.add(my_indices)
>
> This causes that the company object has all indices in my_indices
> (such as Dow Jones S&P 100, Dax, ...) as *choices*.  I.e. someone who
> manipulates these objects via the admin interface is now able to
> choose one or several of them and save the object again. What I want
> to do is choose one or several of the indices in my program and then
> save the object.
>
> Jaroslav
>
> --
> 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.



Help in adding jQuery to my pages

2011-10-28 Thread Leonardo Giordani
Hi all,

I'm trying to add a bit of jQuery to a page in a Django site. It seems
that my jQuery scripts are simply not loaded, while JS scripts work
perfectly.
Evan Firebug does not see the jQuery file as loaded.

This is what I do in base.html

   
       
       
       {% block javascript %}{% endblock %}

and in my page

{% block javascript %}


{% endblock %}

and my tabs.js is

$(document).ready(function() {
$('li').addClass("active");
}

If I edit jquery-1.6.4.js and add something as alert(), this works
perfectly. Other JS scripts work like a charm.

Any suggestion?

Thank you

Leo

-- 
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: Help in adding jQuery to my pages

2011-10-28 Thread Leonardo Giordani
Hi, thank you for your detailed answer.

1. I'm on Django 1.3 (1.3.0-final). I'll take a look at staticfiles
for sure, thanks.
2. I'm getting no errors at all, other JS files in that directory load
perfectly. Firefox can reach them in source view.
3. I'll try it, but it seems to me strange not being able to load and
use jQuery as other JS scripts.

Is that jQuery file of mine (tabs.js) wrong? Is there some stupid
error I cannot spot?

No one is experiencing the problem?

2011/10/28 Andre Terra :
> Hello, Leonardo
>
> First, which django version are you using? I recommend using the contrib
> staticfiles app to handle your static files [1]. Once you get the hang of
> it, it will pay off.
>
> Second, see that you aren't getting 404 errors in the js URL. Using the dev
> server, you can easily read through the status codes returned when loading a
> view. A different solution (sometimes quicker) is hitting Ctrl+U in firefox
> and clicking through the links in  to see the kind of errors you're
> getting.
>
> Finally, if none of that works you could try loading jQuery through the
> Google Libraries Api [2]. Good luck!
>
>
> Cheers,
> AT
>
> [1]
> https://docs.djangoproject.com/en/dev/howto/static-files/#with-a-template-tag
> [2] http://code.google.com/apis/libraries/devguide.html#jquery
>
> On Fri, Oct 28, 2011 at 11:05 AM, Leonardo Giordani
>  wrote:
>>
>> Hi all,
>>
>> I'm trying to add a bit of jQuery to a page in a Django site. It seems
>> that my jQuery scripts are simply not loaded, while JS scripts work
>> perfectly.
>> Evan Firebug does not see the jQuery file as loaded.
>>
>> This is what I do in base.html
>>
>>    
>>        > type="text/css">
>>        
>>        {% block javascript %}{% endblock %}
>>
>> and in my page
>>
>> {% block javascript %}
>> 
>> 
>> {% endblock %}
>>
>> and my tabs.js is
>>
>> $(document).ready(function() {
>>    $('li').addClass("active");
>> }
>>
>> If I edit jquery-1.6.4.js and add something as alert(), this works
>> perfectly. Other JS scripts work like a charm.
>>
>> Any suggestion?
>>
>> Thank you
>>
>> Leo
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Help in adding jQuery to my pages

2011-10-28 Thread Leonardo Giordani
You are right, sorry.

jQuery is loaded, I can see it in Firefox and in Firebug.
If I write this statement

$(document).ready(function() {
}

in a working JS file, that file stops working, can be reached through
Firefox (it is loaded) but not by Firebug.


2011/10/28 Andre Terra :
> I'm sorry if I'm not understanding you, but regarding 2 and 3, if jQuery
> isn't being loaded, shouldn't you be getting a 404 error for the
> jquery-1.6.4.js file?
>
>
> Cheers,
> AT
>
> On Fri, Oct 28, 2011 at 11:30 AM, Leonardo Giordani
>  wrote:
>>
>> Hi, thank you for your detailed answer.
>>
>> 1. I'm on Django 1.3 (1.3.0-final). I'll take a look at staticfiles
>> for sure, thanks.
>> 2. I'm getting no errors at all, other JS files in that directory load
>> perfectly. Firefox can reach them in source view.
>> 3. I'll try it, but it seems to me strange not being able to load and
>> use jQuery as other JS scripts.
>>
>> Is that jQuery file of mine (tabs.js) wrong? Is there some stupid
>> error I cannot spot?
>>
>> No one is experiencing the problem?
>>
>> 2011/10/28 Andre Terra :
>> > Hello, Leonardo
>> >
>> > First, which django version are you using? I recommend using the contrib
>> > staticfiles app to handle your static files [1]. Once you get the hang
>> > of
>> > it, it will pay off.
>> >
>> > Second, see that you aren't getting 404 errors in the js URL. Using the
>> > dev
>> > server, you can easily read through the status codes returned when
>> > loading a
>> > view. A different solution (sometimes quicker) is hitting Ctrl+U in
>> > firefox
>> > and clicking through the links in  to see the kind of errors
>> > you're
>> > getting.
>> >
>> > Finally, if none of that works you could try loading jQuery through the
>> > Google Libraries Api [2]. Good luck!
>> >
>> >
>> > Cheers,
>> > AT
>> >
>> > [1]
>> >
>> > https://docs.djangoproject.com/en/dev/howto/static-files/#with-a-template-tag
>> > [2] http://code.google.com/apis/libraries/devguide.html#jquery
>> >
>> > On Fri, Oct 28, 2011 at 11:05 AM, Leonardo Giordani
>> >  wrote:
>> >>
>> >> Hi all,
>> >>
>> >> I'm trying to add a bit of jQuery to a page in a Django site. It seems
>> >> that my jQuery scripts are simply not loaded, while JS scripts work
>> >> perfectly.
>> >> Evan Firebug does not see the jQuery file as loaded.
>> >>
>> >> This is what I do in base.html
>> >>
>> >>    
>> >>        > >> type="text/css">
>> >>        
>> >>        {% block javascript %}{% endblock %}
>> >>
>> >> and in my page
>> >>
>> >> {% block javascript %}
>> >> 
>> >> 
>> >> {% endblock %}
>> >>
>> >> and my tabs.js is
>> >>
>> >> $(document).ready(function() {
>> >>    $('li').addClass("active");
>> >> }
>> >>
>> >> If I edit jquery-1.6.4.js and add something as alert(), this works
>> >> perfectly. Other JS scripts work like a charm.
>> >>
>> >> Any suggestion?
>> >>
>> >> Thank you
>> >>
>> >> Leo
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "Django users" group.
>> >> To post to this group, send email to django-users@googlegroups.com.
>> >> To unsubscribe from this group, send email to
>> >> django-users+unsubscr...@googlegroups.com.
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/django-users?hl=en.
>> >>
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Django users" group.
>> > To post to this group, send email to django-users@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/django-users?hl=en.
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Help in adding jQuery to my pages

2011-10-28 Thread Leonardo Giordani
Sorry Andy and thank for your patience,

as I though the problem is simply simply bad JQuery.

$(document).ready(function() {
   $('li').addClass("active");
}

what about some ");" to close statements?

Thanks

2011/10/28 Andre Terra :
> I'm sorry if I'm not understanding you, but regarding 2 and 3, if jQuery
> isn't being loaded, shouldn't you be getting a 404 error for the
> jquery-1.6.4.js file?
>
>
> Cheers,
> AT
>
> On Fri, Oct 28, 2011 at 11:30 AM, Leonardo Giordani
>  wrote:
>>
>> Hi, thank you for your detailed answer.
>>
>> 1. I'm on Django 1.3 (1.3.0-final). I'll take a look at staticfiles
>> for sure, thanks.
>> 2. I'm getting no errors at all, other JS files in that directory load
>> perfectly. Firefox can reach them in source view.
>> 3. I'll try it, but it seems to me strange not being able to load and
>> use jQuery as other JS scripts.
>>
>> Is that jQuery file of mine (tabs.js) wrong? Is there some stupid
>> error I cannot spot?
>>
>> No one is experiencing the problem?
>>
>> 2011/10/28 Andre Terra :
>> > Hello, Leonardo
>> >
>> > First, which django version are you using? I recommend using the contrib
>> > staticfiles app to handle your static files [1]. Once you get the hang
>> > of
>> > it, it will pay off.
>> >
>> > Second, see that you aren't getting 404 errors in the js URL. Using the
>> > dev
>> > server, you can easily read through the status codes returned when
>> > loading a
>> > view. A different solution (sometimes quicker) is hitting Ctrl+U in
>> > firefox
>> > and clicking through the links in  to see the kind of errors
>> > you're
>> > getting.
>> >
>> > Finally, if none of that works you could try loading jQuery through the
>> > Google Libraries Api [2]. Good luck!
>> >
>> >
>> > Cheers,
>> > AT
>> >
>> > [1]
>> >
>> > https://docs.djangoproject.com/en/dev/howto/static-files/#with-a-template-tag
>> > [2] http://code.google.com/apis/libraries/devguide.html#jquery
>> >
>> > On Fri, Oct 28, 2011 at 11:05 AM, Leonardo Giordani
>> >  wrote:
>> >>
>> >> Hi all,
>> >>
>> >> I'm trying to add a bit of jQuery to a page in a Django site. It seems
>> >> that my jQuery scripts are simply not loaded, while JS scripts work
>> >> perfectly.
>> >> Evan Firebug does not see the jQuery file as loaded.
>> >>
>> >> This is what I do in base.html
>> >>
>> >>    
>> >>        > >> type="text/css">
>> >>        
>> >>        {% block javascript %}{% endblock %}
>> >>
>> >> and in my page
>> >>
>> >> {% block javascript %}
>> >> 
>> >> 
>> >> {% endblock %}
>> >>
>> >> and my tabs.js is
>> >>
>> >> $(document).ready(function() {
>> >>    $('li').addClass("active");
>> >> }
>> >>
>> >> If I edit jquery-1.6.4.js and add something as alert(), this works
>> >> perfectly. Other JS scripts work like a charm.
>> >>
>> >> Any suggestion?
>> >>
>> >> Thank you
>> >>
>> >> Leo
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "Django users" group.
>> >> To post to this group, send email to django-users@googlegroups.com.
>> >> To unsubscribe from this group, send email to
>> >> django-users+unsubscr...@googlegroups.com.
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/django-users?hl=en.
>> >>
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Django users" group.
>> > To post to this group, send email to django-users@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/django-users?hl=en.
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: CSS reference to Media folder

2012-02-16 Thread Leonardo Giordani
I think it is better for you to keep CSS images in /static folder too.
/media is better suited as a folder to host user-loaded content.

If you keep CSS and images in /static you can just refer to them with
a relative path.

I think that probably (but I'm not sure) CSS can only address relative
paths from their location.

Regards

Leo

2012/2/15 Kolbe :
> Hi all,
>
> I have a .css file in the /static/ folder where I keep all my styles.
>
> Now when I want to refer to images that I use in my CSS that are
> stored in the /media/ folder, how do I reference that?
>
>
> e.g. background-image:url('gradient2.png');
>
> gradient2.png is stored in ~/media/ and my css is in ~/static/
>
> Is there a way to define the path to gradient2.png?
>
> Cheers!
> Max
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Installation steps for Ubuntu 11.10 users

2012-02-20 Thread Leonardo Giordani
Can you detail your problems? I installed it on a 11.10 some time ago and
perhaps I can help you

2012/2/20 jigbox 

> The installation guide has instructions for Ubuntu 10.10 and below
> users.
> However, there is no help for Ubuntu 11.10 users. since I am facing
> some uncommon problems, I request to put up installation steps for
> Ububtu 11.10 users.
> Any help will be appreciated.
>
> --
> 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.



Admin custom widget and add new button

2012-08-08 Thread Leonardo Giordani
Hi all,

I'm trying to enhance a form in the admin site for a given model (Django
1.3). The relevant part of the model is the following

class Project(models.Model):
[...]
icon = models.ForeignKey(Icon, null=True)
[...]

and the admin is a simple call to admin.site.register().

This way I get a very nice form with a drop down menu listing all the Icon
object unicode() calls.

I would like to replace the widget with an image drop down menu made with
javascript, so I did the following

class AdminImageSelectorWidget(forms.Select):
pass

class ProjectForm(forms.ModelForm):
icon = forms.ChoiceField(widget=AdminImageSelectorWidget)
class Meta:
model = Project

class ProjectAdmin(TranslationAdmin):
form = ProjectForm


which is basically just a wrap of the existing structure: by customizing
the render() method of AdminImageSelectorWidget I think I should be able to
get what I want.

First question: is this the correct way to achieve a widget customization?
Second question: by doing this I lose the useful "+" button near the drop
down menu, which lets the users to add a new object. I found that the class
behind this button is RelatedFieldWidgetWrapper, but I do not understand if
I can use it on my widget and how.

Someone can enlighten me?
Thank you very much in advance

Leo

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



Re: Django project and SVN loads older code versions

2012-09-25 Thread Leonardo Giordani
Let me understand: you commit code to a SVN repository and put in in
production? Did you restart Apache?

Leo

2012/9/25 Gjorge Karakabakov 

> I can't explain it but Django + SVN for code version control loads older
> buggy versions of files every time i hit refresh on the web site i'm
> working on.
>
> So if I changed something in a file 2 days ago (made lots of commits since
> then) it will show up now. Next time I hit refresh another change 1 day ago
> appears.
>
> I'm using: Django 1.4, Apache, SVN
>
> --
> 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/-/4UNbERN1NxoJ.
> 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.
>



-- 
Leonardo Giordani

-- 
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: Exception Value: 'Decimal' object is not callable dont no where this is coming from, Any help will be kindly appreciated

2013-09-17 Thread Leonardo Giordani
Hi Maurice,

where do you get this exception? Do you have a Django debug page as output?
Are you calling a view? Can you paste its code?

Leo

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/9/18 MAurice 

> class Loan(models.Model):
> id = models.AutoField(primary_key=True,default=1)
> loan_type   =models.CharField(max_length=20,
> choices=LTYPE,default=1)
> def number():
> no =Account.objects.count()
> if no == None:
> return 10
> else:
> return no + 11
>
>
>
> loan_statement_no=models.IntegerField(('loan_statement_no'),max_length=10,
> unique =True, default=number)
> branch_cod  =models.IntegerField(blank=True, null=True)
> comp_per_ya =models.IntegerField(default=1, help_text="Number
> of compoundings in a year")
> time_years  =models.DecimalField(default=1.0, max_digits=10,
> decimal_places=1)
> loan_number =models.SlugField(unique=True)
> #branch =models.ManyToManyField(Branche)
> start_date  =models.DateField(blank=True,
> null=True,default=datetime.datetime.now())
> end_date=models.DateField(blank=True, null=True)
> no_days =models.IntegerField(default=1)
> account_name=models.ForeignKey(Account)
> loan_amount =models.DecimalField(default=1.0, max_digits=10,
> decimal_places=2)
> interest_rate   =models.DecimalField(default=1.0, max_digits=10,
> decimal_places=2, null=True, blank=True)
> compound_period =models.IntegerField(max_length=64,
> choices=compound_period, default=Yearly)
> loan_fee=models.DecimalField(default=1.0, max_digits=10,
> decimal_places=2, null=True, blank=True)
> ammount_repaid= models.DecimalField(default=1.0, max_digits=10,
> decimal_places=2, null=True, blank=True)
> sd_amount   =models.DecimalField(default=1.0, max_digits=10,
> decimal_places=2, null=True, blank=True)
> dd_amount   =models.DecimalField(default=1.0, max_digits=10,
> decimal_places=2, null=True, blank=True)
> #interest (base) rate
> ib_rate =models.DecimalField(default=1.0, max_digits=10,
> decimal_places=2, null=True, blank=True)
> #interest (penal) rate
> ip_rate =models.DecimalField(default=1.0, max_digits=10,
> decimal_places=2, null=True, blank=True)
> #interest repayment frequency
> ir_frequency
> =models.IntegerField(max_length=64,choices=IRFREQUENCY,default=WEEKLY)
> pr_frequency
> =models.IntegerField(max_length=64,choices=PRFREQUENCY,default=DAILY,help_text="Suggested
> value automatically generated from title. Must be unique.")
>
>
> last_edit_time  = models.TimeField(auto_now=True)
> last_edit_date  = models.DateField(auto_now=True)
>no_of_instalments = models.DecimalField(default=1.0,
> max_digits=10, decimal_places=2, null=True, blank=True)
> no_of_instalments_interest =models.DecimalField(default=1.0,
> max_digits=10, decimal_places=2, null=True, blank=True)
> interest_charged = models.DecimalField(default=1.0, max_digits=10,
> decimal_places=2, editable=False)
>
>
> def save(self, *args, **kwargs):
> i
> self.no_days =(self.end_date - self.start_date).days
> self.required_payment =self.loan_amount
> ((1+(((self.interest_rate)/(self.compound_period))/100))**((self.compound_period)
> * (self.time_years)))
> self.no_of_instalments = (self.no_days) / (self.pr_frequency)
> self.no_of_instalments_interest = (self.no_days) /
> (self.ir_frequency)
>  def name(self):
> return self.account_name.name
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Need help figuring out why my { key:value } doesn't seem to be passed to my view by my javascript file.

2013-09-17 Thread Leonardo Giordani
If I correctly understand you are using jQuery.ajax(). Documentation says
"Data to be sent to the server. It is converted to a query string, if not
already a string. It's appended to the url for GET-requests." So I think
that the ajax() function is calling the URL "/pi/?pathID=somevalue". May
you perhaps check the devel server output?

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/9/18 <7equivale...@gmail.com>

> I have a javascript file that successfully request a Django view. However
> it seems as if it is not passing the key:value pairs. I have created an if
> else statement that test for the key, and it never see's it. Not sure how
> to proceed. Here is my django View and Javascript click function, in the
> view the else statement always executes
>
> def pi_page(request):
>
>   if request.method == "GET":
> get = request.GET.copy()
> if get.has_key('pathID'):
> path_ID = get['pathID']
> path = Path.objects.get(pathID=1)
>#path.pathFill = '#fff'
> path.save()
> variables = RequestContext(request, {'path': path})
> return render_to_response('main_page.html',
> RequestContext(request))
> else:
> path = Path.objects.get(pathID=2)
> path.pathFill = '#eee'
> path.save()
> variables = RequestContext(request, {'path': path})
> return render_to_response('main_page.html',
> RequestContext(request))
>
>
> .click(function(){
> var outputColor =
> document.getElementById("output");
> var outputColorFill =  outputColor.value;
> var pathID = paths[arr[this.id]].pathID;
> var data = { pathID:pathID };
> $.ajax({
> url:"/pi/",
> cache: "false",
> data:data
> });
>
> })
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: while loop in django

2013-09-19 Thread Leonardo Giordani
Can you perhaps better describe what you are trying to do?
Do you need it in a view or in a template?

Regards

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/9/19 Harjot Mann 

> Please tell me how to use while loop indjango so that marks of
> students can be added untill the same roll number is going on?
>
> --
> Harjot Kaur Mann
> Blog: http://harjotmann.wordpress.com/
> Daily Dairy: http://harjotmann.wordpress.com/daily-diary/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: migrating from django 1.3.0 to 1.5.4, getting ImproperlyConfigured exceptions (AUTH_USER_MODEL refers to model 'auth.User' that has not been installed)

2013-09-19 Thread Leonardo Giordani
A question to better understand your problem: do you use a custom User
model in Django 1.3?
Did you perhaps set the AUTH_USER_MODEL=auth.User in your settings.py?

If you do not need a custom user model just drop the AUTH_USER_MODEL
setting variable. Otherwise subclassthe AbstractBaseUser and set your
application's user model in the settings.py file.

Let me know if I correctly understood your issue.

Regards

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/9/18 Lauri Carpenter 

> We have been using django 1.3.0 for a long time.  We are now trying to
> migrate to 1.5.4.  We have not changed any schema or model information.  We
> have been using two layers of middleware and backends (notably something
> based on SSLAuth Django App to authenticate first by certificate issued
> from a trusted authority, then django_auth_ldap to login via ldap if no
> valid certificate is presented). Both of these live on top of whatever
> user/certificate/client/etc. scheme is supported in django 1.3.0.
>
> But under django 1.5.4 we are
> seeing django.core.exceptions.ImproperlyConfigured exceptions
> "AUTH_USER_MODEL refers to model 'auth.User' that has not been installed"
> on the gui page when trying to log in.  The chunk'o'code that handles
> looking for certificate and creating a user if the certificate is presented
> gets this error (so that nobody can use their certificates to log in); then
> the fallback "login" view kicks in, and gets the traceback shown here;
> Traceback:
> File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py" in
> get_response
>   115. response = callback(request,
> *callback_args, **callback_kwargs)
> File "/var/www/lauri/dj/ncis_gui/ncis_gui/src/ncis_gui.py" in login
>   244. return views.login(request, *args, template_name='login.html',
> extra_context=ncis_context, **kwargs)
> File "/usr/lib/python2.6/site-packages/django/views/decorators/debug.py"
> in sensitive_post_parameters_wrapper
>   75. return view(request, *args, **kwargs)
> File "/usr/lib/python2.6/site-packages/django/utils/decorators.py" in
> _wrapped_view
>   91. response = view_func(request, *args, **kwargs)
> File "/usr/lib/python2.6/site-packages/django/views/decorators/cache.py"
> in _wrapped_view_func
>   89. response = view_func(request, *args, **kwargs)
> File "/usr/lib/python2.6/site-packages/django/contrib/auth/views.py" in
> login
>   53. form = authentication_form(request)
> File "/usr/lib/python2.6/site-packages/django/contrib/auth/forms.py" in
> __init__
>   177. UserModel = get_user_model()
> File "/usr/lib/python2.6/site-packages/django/contrib/auth/__init__.py" in
> get_user_model
>   129. raise ImproperlyConfigured("AUTH_USER_MODEL refers to model
> '%s' that has not been installed" % settings.AUTH_USER_MODEL)
>
> Exception Type: ImproperlyConfigured at /login/
> Exception Value: AUTH_USER_MODEL refers to model 'auth.User' that has not
> been installed
>
>
> After googling and reading whatever I could find on the subject (most
> notably
> http://procrastinatingdev.com/django/using-configurable-user-models-in-django-1-5/
>  where
> it expressly says that if you're happy with the existing stuff you don't
> have to change any code) -- I am thoroughly vexed.
>
> What migration step have I missed in order to really use the stuff we were
> using before without changes?
>
> -- lauri
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Need help figuring out why my { key:value } doesn't seem to be passed to my view by my javascript file.

2013-09-19 Thread Leonardo Giordani
In Django key:value are sent the way you specify in your urls
configuration. E.g., say that you want to show an object that you can
extract from your DB with year=2013 and month=09 ('year' and 'month' are
here a primary key for that model if used together). The URL schema is
completely up to you, so you could implement the following solutions

basepath/2013/09/
basepath/2013_09/
basepath/?year=2013&month=09
etc, etc

You have just to implement the correct regular expressions in your URL
specification. (I would strongly adverse the second and the third example,
I used them only to exemplify what you can do).

This is what happens with standard GET requests in your views. POST
requests follow the same schema, but they encompass the form data in the
POST section of the HTTP request (that is available through
self.request.POST in your view).

So the problem you have to figure now is: what is jQuery.ajax() doing?
Sorry but I do not know jQuery AJAX, so I cannot help you on this topic.
Reading the documentation I understand that it is issuing a GET on
"/pi/?pathID=somevalue", so I would implement an URL pattern and a view to
catch this request.

Let me know what happens. Regards

Leo



Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/9/18 <7equivale...@gmail.com>

> "So I think that the ajax() function is calling the URL
> "/pi/?pathID=somevalue," Is that different than how a key:value pair are
> normally sent? I don't know much about this.
> This is the output from the development server...
>
> "GET /pi/ HTTP/1.1" 200 2600
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: while loop in django

2013-09-19 Thread Leonardo Giordani
Harjot,

with so little information is very difficult to help you, you should try to
give a description of your models and exactly what you want to do. What are
the "values" and the "job-id" you are talking about? And what about
"differences"?

About the while loop: in Python it is used this way
http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/whilestatements.html
In Django views (being them Python) you can do the same. In the Django
Template Language there is no while loop available. You can write a tag on
your own, but I suggest you to try and clarify your issue, so that we can
come up with a solution.

Regards,

Leo

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/9/19 Harjot Mann 

> On Thu, Sep 19, 2013 at 12:45 PM, Leonardo Giordani
>  wrote:
> > Can you perhaps better describe what you are trying to do?
> > Do you need it in a view or in a template?
>
>
> In views I want to add two values having same job-id in my app but
> having some other differences. Please tell me how can I do that and
> also I dont know how to use while loop.please tell me.
>
> --
> Harjot Kaur Mann
> Blog: http://harjotmann.wordpress.com/
> Daily Dairy: http://harjotmann.wordpress.com/daily-diary/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Exception Error

2013-09-19 Thread Leonardo Giordani
Ok, can you report the content of
/home/maurice/Desktop/django/Servant/Dashboard/models.py around line 264?
Your error is there.

Simply paste the output of "nl models.py | grep 264 -C 20"

Regards

PS: Rember to reply to the list =)


Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/9/19 Maurice J Elagu 

> TypeError at /admin/Dashboard/loan/add/
>
> 'Decimal' object is not callable
>
> Request Method: POSTRequest URL:
> http://127.0.0.1:8777/admin/Dashboard/loan/add/ Django Version:1.3.1Exception 
> Type:
> TypeError Exception Value:
>
> 'Decimal' object is not callable
>
> Exception Location:/home/maurice/Desktop/django/Servant/Dashboard/models.py
> in save, line 264 Python Executable: /usr/bin/pythonPython Version: 
> 2.7.3Python
> Path:
>
> ['/home/maurice/Desktop/django/Servant',
>  '/usr/lib/python2.7',
>  '/usr/lib/python2.7/plat-linux2',
>  '/usr/lib/python2.7/lib-tk',
>  '/usr/lib/python2.7/lib-old',
>  '/usr/lib/python2.7/lib-dynload',
>  '/usr/local/lib/python2.7/dist-packages',
>  '/usr/lib/python2.7/dist-packages',
>  '/usr/lib/python2.7/dist-packages/PIL',
>  '/usr/lib/python2.7/dist-packages/gst-0.10',
>  '/usr/lib/python2.7/dist-packages/gtk-2.0',
>  '/usr/lib/pymodules/python2.7',
>  '/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
>  '/usr/lib/python2.7/dist-packages/ubuntuone-client',
>  '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
>  '/usr/lib/python2.7/dist-packages/ubuntuone-couch',
>  '/usr/lib/python2.7/dist-packages/ubuntuone-installer',
>  '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol',
>  '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode']
>
> Server time:Wed, 18 Sep 2013 12:17:34 +0300
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Exception Error

2013-09-19 Thread Leonardo Giordani
You are using self.loan_amount, which is an attribute, as a function:
self.load_amount().
I suspect there is a missing sign (+-*/) between self.loan_amount and the
following (
May you confirm this?

Leo



Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/9/19 Maurice J Elagu 

> # line 264 is the formula for compound interest
>
> self.required_payment =self.loan_amount
> ((1+((self.interest_rate/self.compound_period)/100))**(self.compound_period
> * self.time_years))
>
>
> On Thu, Sep 19, 2013 at 4:18 PM, Leonardo Giordani <
> giordani.leona...@gmail.com> wrote:
>
>> Ok, can you report the content of
>> /home/maurice/Desktop/django/Servant/Dashboard/models.py around line 264?
>> Your error is there.
>>
>> Simply paste the output of "nl models.py | grep 264 -C 20"
>>
>> Regards
>>
>> PS: Rember to reply to the list =)
>>
>>
>> Leonardo Giordani
>> Author of The Digital Cat <http://lgiordani.github.com>
>> My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
>> page <https://github.com/lgiordani> - My Coderwall 
>> profile<https://coderwall.com/lgiordani>
>>
>>
>> 2013/9/19 Maurice J Elagu 
>>
>>>  TypeError at /admin/Dashboard/loan/add/
>>>
>>> 'Decimal' object is not callable
>>>
>>> Request Method: POSTRequest URL:
>>> http://127.0.0.1:8777/admin/Dashboard/loan/add/ Django 
>>> Version:1.3.1Exception Type:
>>> TypeError Exception Value:
>>>
>>> 'Decimal' object is not callable
>>>
>>> Exception Location:/home/maurice/Desktop/django/Servant/Dashboard/models.py
>>> in save, line 264 Python Executable: /usr/bin/pythonPython 
>>> Version:2.7.3Python
>>> Path:
>>>
>>> ['/home/maurice/Desktop/django/Servant',
>>>  '/usr/lib/python2.7',
>>>  '/usr/lib/python2.7/plat-linux2',
>>>  '/usr/lib/python2.7/lib-tk',
>>>  '/usr/lib/python2.7/lib-old',
>>>  '/usr/lib/python2.7/lib-dynload',
>>>  '/usr/local/lib/python2.7/dist-packages',
>>>  '/usr/lib/python2.7/dist-packages',
>>>  '/usr/lib/python2.7/dist-packages/PIL',
>>>  '/usr/lib/python2.7/dist-packages/gst-0.10',
>>>  '/usr/lib/python2.7/dist-packages/gtk-2.0',
>>>  '/usr/lib/pymodules/python2.7',
>>>  '/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
>>>  '/usr/lib/python2.7/dist-packages/ubuntuone-client',
>>>  '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
>>>  '/usr/lib/python2.7/dist-packages/ubuntuone-couch',
>>>  '/usr/lib/python2.7/dist-packages/ubuntuone-installer',
>>>  '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol',
>>>  '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode']
>>>
>>> Server time:Wed, 18 Sep 2013 12:17:34 +0300
>>>
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: migrating from django 1.3.0 to 1.5.4, getting ImproperlyConfigured exceptions (AUTH_USER_MODEL refers to model 'auth.User' that has not been installed)

2013-09-19 Thread Leonardo Giordani
The way you are creating the DB is quite complicated, but I suspect that
you are not syncing the base Django applications before doing your magic
stuff. That could be the reason why Django is complaining about the
auth.User not being installed.

I would do the following:

* settings.py with the core apps
* syncdb
* inspectdb
* schemamigration --auto
* migrate

I strongly feel that your problem has to do with Django processing your
models BEFORE doing the base stuff.
Can you try this?

Regards

Leo


Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/9/19 Lauri Carpenter 

> More information:
>
> Interactively, I can get a user_model:
>
> $ python
> Python 2.6.6 (r266:84292, Oct 12 2012, 14:23:48)
> [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from django.contrib.auth import get_user_model
> >>> user_model = get_user_model()
> >>> user_model
> 
> >>>
> >>>
> >>> from django.conf import settings
> >>> settings.AUTH_USER_MODEL
> 'auth.User'
> >>>
>
> (note that the settings.AUTH_USER_MODEL is being calculated by django, not
> set by us; our settings.py file does not include any reference to
> AUTH_USER_anything).
>
> But when this happens during the authentication portion of the web
> interface, it causes the traceback, from somewhere within the
> django.contrib.auth forms for logging in (see traceback in initial
> posting).
>
> -- lauri
>
> On Wednesday, September 18, 2013 12:51:30 PM UTC-5, Lauri Carpenter wrote:
>>
>> We have been using django 1.3.0 for a long time.  We are now trying to
>> migrate to 1.5.4.  We have not changed any schema or model information.  We
>> have been using two layers of middleware and backends (notably something
>> based on SSLAuth Django App to authenticate first by certificate issued
>> from a trusted authority, then django_auth_ldap to login via ldap if no
>> valid certificate is presented). Both of these live on top of whatever
>> user/certificate/client/etc. scheme is supported in django 1.3.0.
>> [snip]
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Need help figuring out why my { key:value } doesn't seem to be passed to my view by my javascript file.

2013-09-19 Thread Leonardo Giordani
I see now that you are not passing the CSRF token, are you?
https://docs.djangoproject.com/en/dev/ref/contrib/csrf/

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/9/18 <7equivale...@gmail.com>

> "So I think that the ajax() function is calling the URL
> "/pi/?pathID=somevalue," Is that different than how a key:value pair are
> normally sent? I don't know much about this.
> This is the output from the development server...
>
> "GET /pi/ HTTP/1.1" 200 2600
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django South - SyntaxError: invalid syntax (, line 1)

2013-10-01 Thread Leonardo Giordani
Can you use the models.py file with the user field on a bare DB?
I mean: if you start from scratch with an empty DB everything works
correctly? You can create Carriers from the Django shell?


Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/9/30 Ivan Goncalves 

> Hi
>
> I'm having trouble with the South.
>
> In the model below:
>
> class Carrier (models.Model):
>  name = models.CharField (max_length = 40, blank = False, null =
> False, verbose_name = 'Name')
>  user = models.ForeignKey (User, blank = True, null = True)
>
>  def save (self, force_insert = False, force_update = False):
>  self.nome self.nome.upper = ()
>  super (Carrier, self). save (force_insert, force_update)
>
>  def __ unicode__ (self):
>  return u '% s'% (self.nome)
>
> the error occurs when i run the migrate after South on the app.
> SyntaxError: invalid syntax (, line 1)
>
> But if my model does not have the user field, then the error message does
> not occur, as shown below:
>
> class Carrier (models.Model):
>  name = models.CharField (max_length = 40, blank = False, null =
> False, verbose_name = 'Name')
>
>  def save (self, force_insert = False, force_update = False):
>  self.nome self.nome.upper = ()
>  super (Carrier, self). save (force_insert, force_update)
>
>  def __ unicode__ (self):
>  return u '% s'% (self.nome)
>
>
> I need the field User. What I have to do ?
>
> Thanks a lot.
>
> Ivan
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/45f2764c-c903-41c2-b692-2afb9f9332ea%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BOmH060TDzmVw%2BOgEdzMKsh1jJPnpn%3DeiZ0rkae7MJPCxQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django-cart. How to run method add_to_cart?

2013-10-01 Thread Leonardo Giordani
You have to implement an URL dispatcher that links an URL to your view.
Read here <https://docs.djangoproject.com/en/dev/topics/http/urls/> and
feel free to ask again if something is still not clear.

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/1 Ricardo 

> Hi, I have this same problem.
> I'm looking for answer everywhere.
> enemybass could implement?
> If someone can help me with this
>
> [] s
>
> Em quarta-feira, 26 de setembro de 2012 05h33min24s UTC-3, enemybass
> escreveu:
>>
>> https://github.com/bmentges/**django-cart<https://github.com/bmentges/django-cart>
>>
>> *I'm* a total *newbie* to *Django. *How to run method *add_to_car*t? In
>> template I would have button "add to cart".
>>
>> Thanks.
>>
>> def add_to_cart(request, product_id, quantity):
>> product = Product.objects.get(id=product**_id)
>> cart = Cart(request)
>> cart.add(product, product.unit_price, quantity)
>>
>> My model look something like this:
>>
>> class Product(models.Model):
>> name = models.CharField(max_length=50**)
>> slug = models.SlugField()
>> unit_price = models.DecimalField(max_digits**=5, decimal_places=2)
>> category = models.ManyToManyField(Categor**y)
>>
>> class Meta:
>> verbose_name = "Product"
>> verbose_name_plural = "Products"
>>
>> def __unicode__(self):
>> return self.name
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/cfabbfd6-01ac-4b40-b887-ea7d7cd59c06%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

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


Re: Django-cart. How to run method add_to_cart?

2013-10-01 Thread Leonardo Giordani
Ricardo,

I think the example on the django-cart site are somehow incorrect: since
you are going to change the database you shall use a POST view and not a
GET.

However, putting apart HTTP verbs for a moment, let's look at how you call
views from URLs. If you write something like the following in your views.py
(or whatever file you mapped in your urls.py)


from django.conf.urls import patterns, url

from django.shortcuts import render_to_response

def my_view(request, product_id, quantity):
[do something with product_id and quantity]
return render_to_response('template.html')

urlpatterns = patterns('',
   url(r'^(?P\d+)/(?P\d+)/$',
   my_view
   )

you can browse to http://yoursite/path/1234/56 and have the Python function
my_view(product_id=1234, quantity=56) called.

Try and implement something like the above code and see if it works.

As for the django_cart: when you modify the DB always use POST views and
not GET, then you are right, you have to return a template rendering in
your add_to_cart() view.

Let me know if it comes to life =)

Cheers,
Leo



Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/1 Ricardo Kamada 

> Leonardo Hi thanks for the reply but I still can not understand.
> I really need to pass the id and quantity parameters in the url? After all
> I'm recording the items in the correct session?
> I saw that the method has no return add_to_cart, as well as other methods
> remove_from_cart.
> In my template I am calling the method like this:
>   
> Buy  
>
> and URLs:
> url (r '^ products / buy / $', 'cart.views.add_to_cart', name =
> 'add_to_cart')
>
> You say that to pass arguments id and quantity that url?
>
> Ricardo
>
>
> 2013/10/1 Leonardo Giordani 
>
>> You have to implement an URL dispatcher that links an URL to your view.
>> Read here <https://docs.djangoproject.com/en/dev/topics/http/urls/> and
>> feel free to ask again if something is still not clear.
>>
>> Leonardo Giordani
>> Author of The Digital Cat <http://lgiordani.github.com>
>> My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
>> page <https://github.com/lgiordani> - My Coderwall 
>> profile<https://coderwall.com/lgiordani>
>>
>>
>> 2013/10/1 Ricardo 
>>
>>>  Hi, I have this same problem.
>>> I'm looking for answer everywhere.
>>> enemybass could implement?
>>> If someone can help me with this
>>>
>>> [] s
>>>
>>> Em quarta-feira, 26 de setembro de 2012 05h33min24s UTC-3, enemybass
>>> escreveu:
>>>>
>>>> https://github.com/bmentges/**django-cart<https://github.com/bmentges/django-cart>
>>>>
>>>> *I'm* a total *newbie* to *Django. *How to run method *add_to_car*t?
>>>> In template I would have button "add to cart".
>>>>
>>>> Thanks.
>>>>
>>>> def add_to_cart(request, product_id, quantity):
>>>> product = Product.objects.get(id=product**_id)
>>>> cart = Cart(request)
>>>> cart.add(product, product.unit_price, quantity)
>>>>
>>>> My model look something like this:
>>>>
>>>> class Product(models.Model):
>>>> name = models.CharField(max_length=50**)
>>>> slug = models.SlugField()
>>>> unit_price = models.DecimalField(max_digits**=5, decimal_places=2)
>>>> category = models.ManyToManyField(Categor**y)
>>>>
>>>> class Meta:
>>>> verbose_name = "Product"
>>>> verbose_name_plural = "Products"
>>>>
>>>> def __unicode__(self):
>>>> return self.name
>>>>
>>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>>
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/cfabbfd6-01ac-4b40-b887-ea7d7cd59c06%4

Re: Django-cart. How to run method add_to_cart?

2013-10-02 Thread Leonardo Giordani
Hi Ricardo,

well this is a question that needs a good explanation. I try to give you
some hints about what you need to research about:

a. You need to send data to the Django server through a POST view. This is
a HTTP "verb", that is one of many different ways the browser has to
communicate with your server. In particular, POST views in Django work just
like standard views (i.e. GET views), but the request object has a POST
attribute which encompasses the data sent by the browser.

b. To create a POST HTTP request in your browser you need to create a form,
and Django can help you with a very very rich API.

So the general roadmap to achieve what you want is:

1. Set up a POST view that processes the incoming data
2. Link the POST view to an URL
3. Create an HTML template which shows a form to the user and sends data
back to the server.

The 3rd point is obviously needed only if you have to show the user a form
to collect the input he or she enters. You can also call POST views
directly, e.g. including some JS that performs the request, but this is an
advanced topic.

Start by looking at this video
tutorial<http://www.youtube.com/watch?v=gQe_8Q4YUpg>and reading the
docs on Django
Forms <https://docs.djangoproject.com/en/dev/topics/forms/>

I'd suggest you to also check the following resources to understand the
previous two matters:

http://www.w3schools.com/tags/ref_httpmethods.asp
https://docs.djangoproject.com/en/dev/ref/request-response/
http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
https://docs.djangoproject.com/en/dev/ref/forms/api/

Feel free to ask more if you need help.

Cheers,

Leo


Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/1 Ricardo Kamada 

> you already helped me a lot =)
> Leonardo looks just http://dpaste.com/1402408/
> On line 20 I pass a value of fixed amount in the template.
> How would get the amount in input dynamically?
>
> Abs
> [] s
>
> Ricardo
>
>
> 2013/10/1 Leonardo Giordani 
>
>> Ricardo,
>>
>> I think the example on the django-cart site are somehow incorrect: since
>> you are going to change the database you shall use a POST view and not a
>> GET.
>>
>> However, putting apart HTTP verbs for a moment, let's look at how you
>> call views from URLs. If you write something like the following in your
>> views.py (or whatever file you mapped in your urls.py)
>>
>>
>> from django.conf.urls import patterns, url
>>
>> from django.shortcuts import render_to_response
>>
>> def my_view(request, product_id, quantity):
>> [do something with product_id and quantity]
>> return render_to_response('template.html')
>>
>> urlpatterns = patterns('',
>>url(r'^(?P\d+)/(?P\d+)/$',
>>my_view
>>)
>>
>> you can browse to http://yoursite/path/1234/56 and have the Python
>> function my_view(product_id=1234, quantity=56) called.
>>
>> Try and implement something like the above code and see if it works.
>>
>> As for the django_cart: when you modify the DB always use POST views and
>> not GET, then you are right, you have to return a template rendering in
>> your add_to_cart() view.
>>
>> Let me know if it comes to life =)
>>
>> Cheers,
>> Leo
>>
>>
>>
>> Leonardo Giordani
>> Author of The Digital Cat <http://lgiordani.github.com>
>> My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
>> page <https://github.com/lgiordani> - My Coderwall 
>> profile<https://coderwall.com/lgiordani>
>>
>>
>> 2013/10/1 Ricardo Kamada 
>>
>>>  Leonardo Hi thanks for the reply but I still can not understand.
>>> I really need to pass the id and quantity parameters in the url? After
>>> all I'm recording the items in the correct session?
>>> I saw that the method has no return add_to_cart, as well as other
>>> methods remove_from_cart.
>>> In my template I am calling the method like this:
>>>  >> detalhe_produto.id1%}"> Buy  
>>>
>>> and URLs:
>>> url (r '^ products / buy / $', 'cart.views.add_to_cart', name =
>>> 'add_to_cart')
>>>
>>> You say that to pass arguments id and quantity that url?
>>>
>>> Ricardo
>>>
>>>
>>> 2013/10/1 Leonardo Giordani 
>>>
>>>&g

Re: Custom Filter: Filter output based on a Python list

2013-10-02 Thread Leonardo Giordani
I'd cycle in the template through a list of exam periods, printing a table
for each cycle.
You have to pass the list of exam periods in the context of your view.

Try and let me know.

Regards,
Leo


Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/2 +Emmanuel 

> Am working on a Django project that retrieves a student's details from the
> database, filters them based on the 'period of examination' (this is
> implemented as a python list in a custom filter) and displays the output.
>
> *Here is my custom filter:*
>
> @register.filter
> def periodofexamination(periodofexam):
> periodofexam = ['DECEMBER 2011', 'MAY 2011', 'DECEMBER 2010']
> for period in periodofexam:
> return period
>
> *The template for displaying the output:*
>
> {% extends 'base.html' %}
> {% load results_extras %}
> {% block title %}My Results{% endblock %}
>
> {% block content %}
>  My Tentative Examination Results
> The results displayed below are tentative
> and for information purposes only.
>
> 
> Course CodeCourse NameCourse
> WorkExamGradeGPAYearExam
> Period
> {% for query in queryset %}
>
> {{
> query.coursecode}}{{query.coursename}}{{query.coursework}}{{query.exam}}{{query.exam|grade}}{{query.exam|gpa}}{{query.academicyear}}{{query.examperiod}}
>
> {% endfor %}
> 
> {% endblock %}
>
> *The output:*
> See the attached file (screenshot.png)
>
> *The challenge:*
> I would like to be able have the student results for a given exam period
> to appear each in their own table, for instance, all the results for exam
> period 'December 2011' should be in one table, all the results for exam
> period 'December 2010' should be in a different table. Currently, all the
> results appear in one table.
> How do I implement this using a custom filter?
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/bed2d4a9-2439-41bd-81a0-be2c4964ca6b%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BO%3DsKK-mb4nMTBf493e%2BJ2483i3Qeuh%3D8qJ8Ckur1qJ%2B%2Bg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Custom Filter: Filter output based on a Python list

2013-10-02 Thread Leonardo Giordani
Can you perhaps paste the view you are using to render the template? So I
can try and help your with some code

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/2 +Emmanuel 

> That's what I have been trying to do for quite sometime now! I can't seem
> to get the code right.
>
>
> On Wednesday, October 2, 2013 2:13:25 PM UTC+3, Leo wrote:
>
>> I'd cycle in the template through a list of exam periods, printing a
>> table for each cycle.
>> You have to pass the list of exam periods in the context of your view.
>>
>> Try and let me know.
>>
>> Regards,
>> Leo
>>
>>
>> Leonardo Giordani
>> Author of The Digital Cat <http://lgiordani.github.com>
>> My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
>> page <https://github.com/lgiordani> - My Coderwall 
>> profile<https://coderwall.com/lgiordani>
>>
>>
>> 2013/10/2 +Emmanuel 
>>
>>> Am working on a Django project that retrieves a student's details from
>>> the database, filters them based on the 'period of examination' (this is
>>> implemented as a python list in a custom filter) and displays the output.
>>>
>>> *Here is my custom filter:*
>>>
>>> @register.filter
>>> def periodofexamination(**periodofexam):
>>> periodofexam = ['DECEMBER 2011', 'MAY 2011', 'DECEMBER 2010']
>>> for period in periodofexam:
>>> return period
>>>
>>> *The template for displaying the output:*
>>>
>>> {% extends 'base.html' %}
>>> {% load results_extras %}
>>> {% block title %}My Results{% endblock %}
>>>
>>> {% block content %}
>>>  My Tentative Examination Results
>>> The results displayed below are tentative
>>> and for information purposes only.
>>>
>>> 
>>> Course CodeCourse NameCourse
>>> WorkExam**GradeGPA**YearExam
>>> Period
>>> {% for query in queryset %}
>>>
>>> {{ query.coursecode}}{{**
>>> query.coursename}}{{**query.coursework}}{{**
>>> query.exam}}{{query.**exam|grade}}{{query.**
>>> exam|gpa}}{{query.**academicyear}}{{**
>>> query.examperiod}}
>>>
>>> {% endfor %}
>>> 
>>> {% endblock %}
>>>
>>> *The output:*
>>> See the attached file (screenshot.png)
>>>
>>> *The challenge:*
>>> I would like to be able have the student results for a given exam period
>>> to appear each in their own table, for instance, all the results for exam
>>> period 'December 2011' should be in one table, all the results for exam
>>> period 'December 2010' should be in a different table. Currently, all the
>>> results appear in one table.
>>> How do I implement this using a custom filter?
>>> Thanks.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@**googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>>
>>> Visit this group at 
>>> http://groups.google.com/**group/django-users<http://groups.google.com/group/django-users>
>>> .
>>> To view this discussion on the web visit https://groups.google.com/d/**
>>> msgid/django-users/bed2d4a9-**2439-41bd-81a0-be2c4964ca6b%**
>>> 40googlegroups.com<https://groups.google.com/d/msgid/django-users/bed2d4a9-2439-41bd-81a0-be2c4964ca6b%40googlegroups.com>
>>> .
>>> For more options, visit 
>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>> .
>>>
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8bb1abd1-7cc4-44a4-aba4-2087b88d554d%40googlegroups.com
> .
>
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BOnt7phVNgR5F13Jo4CgRW_of%2BU%3D86N%2BOjnY5YzfSg3jJA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Custom Filter: Filter output based on a Python list

2013-10-02 Thread Leonardo Giordani
Ok, now I get the point. I STRONGLY suggest to avoid performing big
computations while rendering templates, so I think it is better for you to
try something like

def results_page(request):
context = {}
context.update(locals())
context['periods'] = {}
for period in ['DECEMBER 2011', 'MAY 2011', 'DECEMBER 2010']:
context['periods'][period] = Results.objects.all().filter(\
   reg_number =
'DBA/20020/82/DU').filter()
return render_to_response('results.html', context, context_instance =
RequestContext(request))

and in template

{% for period,results in periods.items %}

[...]
Here you can use {{period}}, which is in turn 'DECEMBER 2011', 'MAY
2011', and so on, and
{{result}} that encompasses the values extracted from the DB.
[...]

{% endfor %}

I included a filter() since I do not know the
models, so I do not know how you can filter out by examination period.

Please note that I would not pass the whole locals() dict to the view, but
carefully select what I need in the template.

Speaking about your filter

@register.filter
def periodofexamination(periodofexam):
periodofexam = ['DECEMBER 2011', 'MAY 2011', 'DECEMBER 2010']
for period in periodofexam:
return period

I think you misunderstood the filter role, which is, indeed, to filter,
things. Here, the input periodofexam variable is not filtered, but
overwritten. Furthermore, you use return in a for loop, so the result of
your filter is 'DECEMBER 2011' irrespective of the input value.

Please check the above code, I wrote it directly in the mail composer, so
bugs are certainly lurking.

Let me know if you succeed in solving the problem

Leo




Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/2 +Emmanuel 

> Here's the view:
> def results_page(request):
> queryset = Results.objects.all().filter(reg_number = 'DBA/20020/82/DU')
> return render_to_response('results.html', locals(), context_instance =
> RequestContext(request))
>
> Please note that, so far, there's nothing wrong with the view. Using the
> custom filter at the output level is where the issue is.
> What I want to do is something close to this (note the bold items):
>
> *{% for query in queryset|periodofexamination %}*
> 
> Course CodeCourse NameCourse
> WorkExamGradeGPAYearExam
> Period
>
> {{
> query.coursecode}}{{query.coursename}}{{query.coursework}}{{query.exam}}{{query.exam|grade}}{{query.exam|gpa}}{{query.academicyear}}{{query.examperiod}}
>
> 
> {% endfor %}
> {% endblock %}
>
> On Wednesday, October 2, 2013 3:00:40 PM UTC+3, Leo wrote:
>
>> Can you perhaps paste the view you are using to render the template? So I
>> can try and help your with some code
>>
>> Leonardo Giordani
>> Author of The Digital Cat <http://lgiordani.github.com>
>> My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
>> page <https://github.com/lgiordani> - My Coderwall 
>> profile<https://coderwall.com/lgiordani>
>>
>>
>> 2013/10/2 +Emmanuel 
>>
>>> That's what I have been trying to do for quite sometime now! I can't
>>> seem to get the code right.
>>>
>>>
>>> On Wednesday, October 2, 2013 2:13:25 PM UTC+3, Leo wrote:
>>>
>>>> I'd cycle in the template through a list of exam periods, printing a
>>>> table for each cycle.
>>>> You have to pass the list of exam periods in the context of your view.
>>>>
>>>> Try and let me know.
>>>>
>>>> Regards,
>>>> Leo
>>>>
>>>>
>>>> Leonardo Giordani
>>>> Author of The Digital Cat <http://lgiordani.github.com>
>>>> My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
>>>> page <https://github.com/lgiordani> - My Coderwall 
>>>> profile<https://coderwall.com/lgiordani>
>>>>
>>>>
>>>> 2013/10/2 +Emmanuel 
>>>>
>>>>>  Am working on a Django project that retrieves a student's details
>>>>> from the database, filters them based on the 'period of examination' (this
>>>>> is implemented as a python list in a custom filter) and displays the 
>>>>> output.
>>>>>
>>>>> *Here is my custom filter:

Re: model inheritance

2013-10-02 Thread Leonardo Giordani
Are you sure your DB has been synced after putting the ForeignKey(News) in
your Department model?
Can you post somewhere the following models: News, OldNews, Department?

Regards,

Leo

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/2 Roberto López López 

>  Hi,
>
> I am extending a 3rd party model in my application, using multi-table
> inheritance. I can create an instance and modify it, but when I try to list
> the created objects at http://localhost:8000/en/admin/news/news/ , I am
> getting a nice exception:
>
> Traceback:
> File
> "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/core/handlers/base.py"
> in get_response
>   140. response = response.render()
> File
> "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/response.py"
> in render
>   105. self.content = self.rendered_content
> File
> "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/response.py"
> in rendered_content
>   82. content = template.render(context)
> File
> "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/base.py"
> in render
>   140. return self._render(context)
> File
> "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/base.py"
> in _render
>   134. return self.nodelist.render(context)
> File
> "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/base.py"
> in render
>   830. bit = self.render_node(node, context)
> File
> "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/debug.py"
> in render_node
>   74. return node.render(context)
> File
> "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/loader_tags.py"
> in render
>   124. return compiled_parent._render(context)
> File
> "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/base.py"
> in _render
>   134. return self.nodelist.render(context)
> File
> "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/base.py"
> in render
>   830. bit = self.render_node(node, context)
> File
> "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/debug.py"
> in render_node
>   74. return node.render(context)
> File
> "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/loader_tags.py"
> in render
>   124. return compiled_parent._render(context)
> File
> "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/base.py"
> in _render
>   134. return self.nodelist.render(context)
> File
> "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/base.py"
> in render
>   830. bit = self.render_node(node, context)
> File
> "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/debug.py"
> in render_node
>   74. return node.render(context)
> File
> "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/loader_tags.py"
> in render
>   63. result = block.nodelist.render(context)
> File
> "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/base.py"
> in render
>   830. bit = self.render_node(node, context)
> File
> "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/debug.py"
> in render_node
>   74. return node.render(context)
> File
> "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/loader_tags.py"
> in render
>   63. result = block.nodelist.render(context)
> File
> "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/base.py"
> in render
>   830. bit = self.render_node(node, context)
> File
> "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/template/debug.py"
> in render_node
>   74. return node.render(context)
> File
> "/home/roberto/.virtualenvs/ve_news/lo

Re: uptodate Account_balance

2013-10-03 Thread Leonardo Giordani
Maurice,

please remember not everyone on this ML knows finance and noone knows your
application but you.
Moreover, people on ML cannot spend hours trying to figure out what is your
problem: sometimes just solving the problem needs a lot of work, so make
things easy.

You posted your models, but I think you are implementing some views or at
least using them in some code.
Can you give some details about the procedure you are implementing and the
exact issue tou are facing?

Cheers,

Leo

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/3 MAurice 

> Hello everyone was requesting for help on this micro-finance software am
> developing, needed to make the account balance reflect updated
> amount/value on the database when deposits/withdraws are made on either the
> account or loan repayment
>
> *class Branch(models.Model):*
> time_stamp =models.DateTimeField(default=datetime.datetime.now(),
> editable=False)
> name =models.CharField(max_length=200)
> physical_location=models.CharField(max_length=200)
> email=models.EmailField()
>
> *class Account(models.Model):*
> account_type=models.CharField(max_length=200, choices=ACCTYPE)
> branch=models.ForeignKey('Branch')
> first_name=models.CharField(max_length=200)
> last_name   =models.CharField(max_length=200)
> account_number =models.SlugField(unique=True)
> account_current_balance =models.FloatField(max_length=255,default=0)
> *
> class Account_holder(models.Model):*
> id =models.IntegerField(primary_key=True,default=1)
> account_id =models.ManyToManyField(Account)
>
>
> *
>
> class Loan(models.Model):*
> id = models.AutoField(primary_key=True,default=1)
> branch_cod=models.IntegerField(blank=True, null=True)
> time_years=models.DecimalField(default=1.0, max_digits=10,
> decimal_places=4)
> loan_number =models.SlugField(unique=True)
> account_name=models.ForeignKey(Account)
> loan_amount=models.DecimalField(default=0.0, max_digits=10,
> decimal_places=2)
> interest_rate=models.DecimalField(default=0.0, max_digits=10,
> decimal_places=2)
> interest_charged = models.DecimalField(default=0.0, max_digits=10,
> decimal_places=2, editable=False)
> required_payement = models.DecimalField(default=1.0, max_digits=10,
> decimal_places=2)
> *
> class statement(models.Model):*
> account_id =models.ForeignKey(Account)
>  date = models.DateTimeField(default=datetime.datetime.now(),
> editable=False)
>  deposit = models.PositiveIntegerField(null=True, default=0)
>  withdraw = models.PositiveIntegerField(null=True, default=0)
>  description =models.TextField(max_length=200)
>  current_balance = models.FloatField(max_length=200, editable=False)
>
> def save(self, *args, **kwargs):
>  self.current_balance =  self.account_id.average_balance +
> self.credit - self.debit
>  self.average_balance = self.account_id.average_balance +
> self.credit - self.debit -self.minimum_balance
>  super(statement,self).save(*args, **kwargs)
> *
>  class Savant_user(models.Model):*
>   user =models.OneToOneField(User)
>   branch =models.ManyToManyField('Branch')
>
>
>
>   def create_Dashboard_user_callback(sender, instance, **kwargs):
>   Dashboard, new = Savant_user.objects.get_or_create(user=instance)
>   post_save.connect(create_Dashboard_user_callback, User)
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/585a5845-9111-492d-a0c9-10342ee2bfbc%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BOnGAFK4v-WUPbmLzzK-Ju8EqKpAtLc6SbffScwKV0DCVA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Custom Filter: Filter output based on a Python list

2013-10-04 Thread Leonardo Giordani
Emmanuel,

for examperiod I'd simply write

[...]
for period in ['DECEMBER 2011', 'MAY 2011', 'DECEMBER 2010']:
context['periods'][period] = Results.objects.all().filter(\
   reg_number = 'DBA/20020/82/DU').filter(examperiod=period)
[...]

Just be careful when dealing with such comparisons since values must be
exactly the same; to state it clearly: this works always if the period
strings ("DECEMBER 2011", ...) are machine-generated and do not come from a
form (user input).

However, check this
page<https://docs.djangoproject.com/en/dev/topics/db/queries/>which
contains a very detailed analysis of Django query system.

Speaking about the templates: first of all do not take my code as the
source of the truth, things can be done in several ways.
Given that, I try to give you a bigger picture that hopefully helps you
understanding how to step further.

When introducing Django I always stress the separation between views and
templates, which is the base concept of the whole framework (MVT -
Model/View/Template).
Views are Python functions. Their purpose is to produce data and to return
data, just like any function in this world =)
Jokes apart, views are MOST OF THE TIME used to fetch data from the DB
through models and to return templates rendered in HTTP responses, so that
a browser can show them.

So, putting it simply: views extract data, templates show them (this is
somehow simplistic, but is a good starting point).

Templates are text files that are joined with a dictionary through the
Django template language. Most notably you can insert in the template
elements of the dictionary just inserting "{{ key }}" where "key" is the
dictionary key you want to fetch. If the value you get from the dictionary
is an object or another dictionary, you can use the dotted notation to
access its attributes or keys. So if you write in a template {{ obj }} the
template expects you to pass a dictionary which contains the key 'obj' and
some value that can be printed. If you write {{ obj.name }} the template
expects you to pass a dictionary that contains the key 'obj', which in turn
is something that can be accessed through the 'name' attribute lookup; for
example, a Python object with a 'name' attribute.

Context is the dictionary that the view passes to the template when calling
render_to_response().

So my advice was to select what you pass in the context, since passing
locals() is overkill; you pass the template every variable you have, and
this can result in passing a very big dictionary! Moreover, it is not clear
to another programmer (that is you in a month) what the template really
needs. If you template is made to represent a set of objects in table just
extract the set of objects and pass them to the view. To give you an
example:

*MODEL*
class Exam(models.Model):
label = models.CharField(max_length=30)

*VIEW*
def someview(request):
my_list_of_objects = Exam.objects.filter(label='somelabel')
context = {'objects':my_list_of_objects}
return render_to_response('results.html', context, context_instance =
RequestContext(request))

*TEMPLATE*
[...]

{% for obj in objects %}
{{obj.label}}
{% endfor %}

[...]

This can also be written (and is perfectly correct):

*VIEW*
def someview(request):
my_list_of_objects = *[exam.label for exam
in*Exam.objects.filter(label='somelabel')
*]*
context = {'object':my_list_of_object}
return render_to_response('results.html', context, context_instance =
RequestContext(request))

*TEMPLATE*
[...]

{% for obj in objects %}
{{obj}}
{% endfor %}

[...]

(Please note that in the second example I left the previous nomenclature
for clarity's sake - in a real case I'd call the values 'labels' and not
'objects')

Hope this helps you. Regards,

Leo

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/3 +Emmanuel 

> Thanks for the update and the code. Been trying to make sense of the code
> and trying to get it to work. This is my first project so I still have some
> challenges:
>
>
>- My model contains a field examperiod = models.CharField(max_length =
>100) which I need to use to filter. How exactly do I apply that in
>. I can't seem to get it to work.
>- The code you provided to be used in the template is a little
>difficult for me to comprehend. Previously, I could use query.coursecode,
>query.examcode, etc to populate the specific cells in the table. I
>can't seem to figure out how to do that with the new piece of code.
&g

Re: Custom Filter: Filter output based on a Python list

2013-10-05 Thread Leonardo Giordani
You are welcome! I hope you succeed in your work.

Cheers,

Leo
Il 05/ott/2013 22:42 "+Emmanuel"  ha scritto:

> Leo,
> Finally got it working and was able to display the data in the respective
> table as desired. Thank you very much.
>
> I appreciate you patience in helping me understand the 'why' and not just
> 'how' I should do it in a particular way; and for the advice on Django best
> practices. I can't thank you enough!
>
> On Friday, October 4, 2013 10:23:38 AM UTC+3, Leo wrote:
>>
>> Emmanuel,
>>
>> for examperiod I'd simply write
>>
>> [...]
>> for period in ['DECEMBER 2011', 'MAY 2011', 'DECEMBER 2010']:
>> context['periods'][period] = Results.objects.all().filter(\
>>reg_number = 'DBA/20020/82/DU').filter(**
>> examperiod=period)
>> [...]
>>
>> Just be careful when dealing with such comparisons since values must be
>> exactly the same; to state it clearly: this works always if the period
>> strings ("DECEMBER 2011", ...) are machine-generated and do not come from a
>> form (user input).
>>
>> However, check this 
>> page<https://docs.djangoproject.com/en/dev/topics/db/queries/>which contains 
>> a very detailed analysis of Django query system.
>>
>> Speaking about the templates: first of all do not take my code as the
>> source of the truth, things can be done in several ways.
>> Given that, I try to give you a bigger picture that hopefully helps you
>> understanding how to step further.
>>
>> When introducing Django I always stress the separation between views and
>> templates, which is the base concept of the whole framework (MVT -
>> Model/View/Template).
>> Views are Python functions. Their purpose is to produce data and to
>> return data, just like any function in this world =)
>> Jokes apart, views are MOST OF THE TIME used to fetch data from the DB
>> through models and to return templates rendered in HTTP responses, so that
>> a browser can show them.
>>
>> So, putting it simply: views extract data, templates show them (this is
>> somehow simplistic, but is a good starting point).
>>
>> Templates are text files that are joined with a dictionary through the
>> Django template language. Most notably you can insert in the template
>> elements of the dictionary just inserting "{{ key }}" where "key" is the
>> dictionary key you want to fetch. If the value you get from the dictionary
>> is an object or another dictionary, you can use the dotted notation to
>> access its attributes or keys. So if you write in a template {{ obj }} the
>> template expects you to pass a dictionary which contains the key 'obj' and
>> some value that can be printed. If you write {{ obj.name }} the template
>> expects you to pass a dictionary that contains the key 'obj', which in turn
>> is something that can be accessed through the 'name' attribute lookup; for
>> example, a Python object with a 'name' attribute.
>>
>> Context is the dictionary that the view passes to the template when
>> calling render_to_response().
>>
>> So my advice was to select what you pass in the context, since passing
>> locals() is overkill; you pass the template every variable you have, and
>> this can result in passing a very big dictionary! Moreover, it is not clear
>> to another programmer (that is you in a month) what the template really
>> needs. If you template is made to represent a set of objects in table just
>> extract the set of objects and pass them to the view. To give you an
>> example:
>>
>> *MODEL*
>> class Exam(models.Model):
>> label = models.CharField(max_length=**30)
>>
>> *VIEW*
>> def someview(request):
>> my_list_of_objects = Exam.objects.filter(label='**somelabel')
>> context = {'objects':my_list_of_objects}
>> return render_to_response('results.**html', context,
>> context_instance = RequestContext(request))
>>
>> *TEMPLATE*
>> [...]
>> 
>> {% for obj in objects %}
>> {{obj.label}}
>> {% endfor %}
>> 
>> [...]
>>
>> This can also be written (and is perfectly correct):
>>
>> *VIEW*
>> def someview(request):
>> my_list_of_objects = *[exam.label for exam in*Exam.objects.filter(label='
>> **somelabel')*]*
>> context = {'object':my_list_of_object}
>> return render_to_response('results.**h

Re: logic problem

2013-10-06 Thread Leonardo Giordani
Are you sure that your DB contains only one entry with that name?
Try printing it in the view you use to render that template and check the
output of the development server.


Cheers,

Leo

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/7 Harjot Mann 

> In my app I am selecting the two tests but both appear with both
> materials like this
>
> http://screencloud.net/v/EKF7
>
> I want that in the first row depth 0 to 0 should appear but in the
> second row  only depth 10 to 20 should come. The code is here:
> http://tny.cz/019515d5
>
>
> --
> Harjot Kaur Mann
> Blog: http://harjotmann.wordpress.com/
> Daily Dairy: http://harjotmann.wordpress.com/daily-diary/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAB0GQhAGZJRR-xCGeqyEZd-bDgVEp%3DwA5ae6Yt7hJrxihoXAqw%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BOkpa5PsBU1BuyNkTNf550p6KjQdf%2BQ%3DN4%3Dn2dM6uT58pw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Query field with reference

2013-10-08 Thread Leonardo Giordani
I do not know MongoDB, so sorry if I get it wrong. I'd say that you have to
write

*result = [a.get_json() for a in
Player.objects.filter(position__position_name='DD')]
*
since in your attached document you set it this way (line 53).
Try and let me know

Leo


Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/8 Hélio Miranda 

> Hi
> I was trying to make a query in a field that has refencia to another
> collection, like this:
> *result = [a.get_json() for a in
> Player.objects.filter(position__name='DD')]*
>
> But it is returning me empty, and I have a player with the position DD
> I'm using mongodb as a database.
>
> In my Document is thus:
> http://plnkr.co/edit/FHH2hZh26OiLMKTk2ToO?p=info
>
> Does anyone know what I'm doing wrong?
>
> thank you
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/47c58f74-484b-4668-9678-7a50fdea842f%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BOmUqH2kfcY-Ve0%3D9-HHAtP9sd%2BpyT-358PO9M5Cyq4J%3Dg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django query from database

2013-10-11 Thread Leonardo Giordani
I think that you have to perform a query for each Code, extracting the list
of Word matching that Code and then merging all the lists.
Since I don't know your models, I'll give you some general code, let me
know if you understand how to implement it exactly on your models.

Assuming that the CodeTable is the representation of a Word model:

B = []
for code in A:
words = Word.objects.filter(code=code)
B.extend(words)

This is the basic algorithm. You can then make all sorts of Python magic
tricks to shorten it or make it faster, but if you are not dealing with
billions of data I do suggest you to keep it simple and readable.

If you need to have each element in B appear just one time (uniqueness)
just perform a B = set(B) at the end.

Let me know if it works. =)

Cheers
Leo



Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/11 Kamal Kaur 

> Hello there,
>
> Hope you are doing well :)
>
> I have a problem regarding querying a list from two tables, the
> procedure goes like:
>
> Considering two tables from mysql database:
>
> 1. UserProfile table, with complete client details: First name, Last
> name, Address, email id, Contact number etc.
> 2. CodeTable, with only two columns 'Word' and 'Code'. Codes are
> soundex codes for the words in first column like:
>
> WordCode
> DavidD130
> Henry   H560
> OstroO236
> Milton   M435
> HenrooH560
>
> These 'words' are also contained in UserProfile table somewhere, can
> be in any column. I have a list A with soundex codes, entered by user,
> obtained with request.GET like:
> A= ['D130', 'H560', 'O236']
>
> Here starts the problem, I have to fetch 'Words' from CodeTable
> corresponding to the 'Codes' in list A, meaning that I need another
> list B, like:
>
> B = ['David', 'Henry', 'Ostro', ' Henroo']
>
> Because the code H560 is same for ' Henroo', it will also be there in
> list B as we are searching for all the words that have 'codes' in list
> A.
>
> For this list B, I want to search all the client details i.e. I want
> to display all the clients that have any of the words in list B from
> UserProfile table.
>
> I am not getting how to accomplish this searching using Django
> queries. I am not able to make a view/function for this logic. Please
> help and feel free to ask details if problm is not clear.
>
> Thanks ^_^
>
>
> --
> Kamaljeet Kaur
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAP8Q%2BxhO%3DeZJjdui4OOw1T3V2QqtJW_PnC-BTTCDdBogipc8sw%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BO%3DFRyds-AOGAOd47mRgtjEz5u4TAKVx6S%2BPNQ5Qfb3WDg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django query from database

2013-10-11 Thread Leonardo Giordani
Sorry, I forgot the User part of your question.

Let me understand the exact relationship between codes, words and users: do
those words or codes come from a form? Or are saved in the DB for each user?

I ask this because I want to understand if you are trying to get a
relationship that already exists on the DB (so it is a problem of doing
good queries and building smart Python structures) or if you are trying to
manage some new data the user enters in your site.

If you find the time to better describe the exact flow of your application
I hope I can help you find a good solution for your problem.

Cheers

Leo

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/11 Kamal Kaur 

> On Fri, Oct 11, 2013 at 4:06 PM, Leonardo Giordani
>  wrote:
> > I think that you have to perform a query for each Code, extracting the
> list
> > of Word matching that Code and then merging all the lists.
>
> Exactly!
>
> > Since I don't know your models, I'll give you some general code, let me
> know
> > if you understand how to implement it exactly on your models.
>
> Here are these two models: http://tny.cz/82158e83
>
> 
> > This is the basic algorithm. You can then make all sorts of Python magic
> > tricks to shorten it or make it faster, but if you are not dealing with
> > billions of data I do suggest you to keep it simple and readable.
>
> Ok.
>
> > If you need to have each element in B appear just one time (uniqueness)
> just
> > perform a B = set(B) at the end.
>
> Ok.
>
> > Let me know if it works. =)
>
> Yes it will work! But after extending list B, I want to search the
> elements of list B from UserProfile table. Here the word can be
> anywhere and can be more than one times. Also two words in list B can
> be in same column. Here also the results must be unique.
>
> Also how to get the output in a template? The tuples containing
> elements of list B from UserProfile table are to be displayed in that
> template.
>
> Thanks ^_^
>
> --
> Kamaljeet Kaur
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAP8Q%2BxidZD%2B6mo2z4POabcX_WBFPvEk%3D%3Dg%2BOPNET6u0SYmM%3DkQ%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BOm7A9kugRpE4S%2BmHLnRvYtO9w5RF9ZsWNwZzWxvxgBkVQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Django query from database

2013-10-11 Thread Leonardo Giordani
Ok, I think I got the point.

So, correct me if I didn't get it right, you have to get users which have
first_name, last_name, or other fields equal to the words in your list B.

This can be accomplished by looking at each field for each keyword. I would
also compile a dictionary keeping reference of what field matches the search
Continuing the code I wrote above:

users = {}
for field in ['first_name', 'last_name']:
# build something like {'first_name__in', ['David', 'Henry', 'Ostro', '
Henroo']}
filter_dict = {field + '__in': B}

# find all users that match
results = User.objects.filter(**filter_dict)

# store each user and the list of its fields that match the search
for user in results:
try:
   users[user].append(field)
except KeyError:
users[user] = [field]

This is perhaps the worst Python code I ever wrote, but I hope you can
tolerate it. Also beware that it is written directly in the mail composer
(so indentation is wrong and code is untested).

Now I realize that the "__in" trick can be used also for the first code I
wrote, try it.

As for the template, you can pass the users dict in the context. In the
template loop over the key/values with

{% for user,fields in users.iteritems %}
{% endfor %}

inside this loop you can further loop over fields with

{% for field in fields %}
{% endfor %}

I am not sure if inside this last loop you can write something like

{{ user.field }}

since I have to check if the template attribute retrieving syntax also
performs getattr. if this does not work you have to store tuples as values
of the users dict, instead of fields, each tuple being (field,
getattr(user, field)).

Try to give a sense to all this stuff and let me know!

Cheers,
Leo



Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/11 Kamal Kaur 

> On Fri, Oct 11, 2013 at 6:43 PM, Leonardo Giordani
>  wrote:
> > Sorry, I forgot the User part of your question.
> >
> > Let me understand the exact relationship between codes, words and users:
> do
> > those words or codes come from a form? Or are saved in the DB for each
> user?
>
> Actually I have to search for client details (from UserProfile table)
> ignoring vowels. Because new users come from time to time. During
> their registration, the phonetic codes of all the words entered are
> saved (in CodeTable) along with the actual word.
>
> When a string is searched for, in search box, it is split into words
> and then these words are converted to phonetic codes which are to be
> searched in CodeTable. The words corresponding to matching codes will
> be searched for in UserProfile table which will be given as output for
> searched keywords i.e No matter if a user enters "Smyth" or "Smith",
> output will be on the basis of their sound. And thats all :)
>
> 
>
> > If you find the time to better describe the exact flow of your
> application I
> > hope I can help you find a good solution for your problem.
>
> Here you go :)
>
> --
> Kamaljeet Kaur
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAP8Q%2Bxi-%2BPibMh_DsMyf14UUpZ_BkSEw5nWTRkdYyzoCDkpJWA%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BO%3DA%2B1MrXVBEYVS6fhvXGG4Yiem5t6wKdjzrfLnRG62QNw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: View for creating, listing, and deleting

2013-10-14 Thread Leonardo Giordani
Hi,

you are submitting two different problems, if I correctly understand your
question. The first is about Create Read Update Delete objects, the second
is about code reuse.

1. CRUD
>From the user's point of view you should create a page with the list of
objects, then provide a way to selectively delete some of them, and a way
to create a new object.
For example you could have a button near each object that deletes it, and a
general button that creates a new object.

The create button shall perform a GET on a page with a form, which in turn,
when saved, shall perform a POST. This is done by a view (CreateView, if
you want to use class based generic views). The delete button shall perform
a POST, and this is usually done by hiding a prefilled form and submitting
it through JS when pressing the delete button.

2. Code reuse
Since class-based generic views get a model as a parameter, I'd create a
Factory, i.e. a class that returns a class. You can then loop over your
models and call the Factory, generating urls on-th-fly.


Does this make sense for you? Let me know
Cheers,

Leo


Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/12 

> I'm working on a project in which on a certain page I want to have a list
> of objects as well as the ability to delete and create them. I know that
> there are class-based generic views for these things, but I don't want
> three separate pages for these operations. What would be the best way to
> have them all on one page?
>
> I'm guessing the right way to do it is to make a new class-based view for
> viewing, deleting, and listing objects of a certain kind and then to
> subclass for every object I need to list, create, or view, but I thought
> I'd make sure that's the best way to do it first.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/44556c9b-8712-401c-b92b-62e124d1c93c%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

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


Re: AttributeError: 'module' object has no attribute '_handlerList'

2013-10-14 Thread Leonardo Giordani
Hi, are you using a virtualenv? In that case, can you post the list of
packages you installed? If not, can you give details about the OS you are
working on, Django version, and so on?

Regards,

Leo

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/14 Darion Yaphet 

> Hi all :
>
> when I use django-admin.py to init django project
> django-admin.py  startproject hello
>
> Got a exception ..
>  AttributeError: 'module' object has no attribute '_handlerList'
>
> what is it 
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a6024b53-9203-4e25-9202-d2cdf017e5a0%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BO%3Dr_nPHCA4T3N1hX8--be1R9SMtB%3Deaa_5cFsPCravawg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: AttributeError: 'module' object has no attribute '_handlerList'

2013-10-14 Thread Leonardo Giordani
Please give me the information I asked you, otherwise I cannot figure out
what kind of problem you have.

Are you using a virtualenv? In that case, can you post the list of packages
you installed? If not, can you give details about the OS you are working on?

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/14 Darion Yaphet 

> Python  2.7.3 and Django is 1.5.3 ..
>
>
> 2013/10/14 Leonardo Giordani 
>
>> Hi, are you using a virtualenv? In that case, can you post the list of
>> packages you installed? If not, can you give details about the OS you are
>> working on, Django version, and so on?
>>
>> Regards,
>>
>> Leo
>>
>> Leonardo Giordani
>> Author of The Digital Cat <http://lgiordani.github.com>
>> My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
>> page <https://github.com/lgiordani> - My Coderwall 
>> profile<https://coderwall.com/lgiordani>
>>
>>
>> 2013/10/14 Darion Yaphet 
>>
>>> Hi all :
>>>
>>> when I use django-admin.py to init django project
>>> django-admin.py  startproject hello
>>>
>>> Got a exception ..
>>>  AttributeError: 'module' object has no attribute '_handlerList'
>>>
>>> what is it 
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/a6024b53-9203-4e25-9202-d2cdf017e5a0%40googlegroups.com
>>> .
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAEhE%2BO%3Dr_nPHCA4T3N1hX8--be1R9SMtB%3Deaa_5cFsPCravawg%40mail.gmail.com
>> .
>>
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>
>
> --
>
>
> long is the way and hard  that out of Hell leads up to light
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAOHWcC%2BjyqOZBjqSYVHYNZm7vbixRiWtBQ2dvteYLdv%3DNhyi6w%40mail.gmail.com
> .
>
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BO%3D-D_WzBa4_Lis4Bppak-czSKG9D60b91b7GFSWvnWM%2Bw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: AttributeError: 'module' object has no attribute '_handlerList'

2013-10-14 Thread Leonardo Giordani
Ok, can you please try to traceback the command and post the results?

python django-admin.py startproject hello --traceback



Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/15 Darion Yaphet 

> ok I built Django 1.5.3  on  fedora 18  and  don't use virtualenv
>
>
> 2013/10/14 Leonardo Giordani 
>
>> Please give me the information I asked you, otherwise I cannot figure out
>> what kind of problem you have.
>>
>> Are you using a virtualenv? In that case, can you post the list of
>> packages you installed? If not, can you give details about the OS you are
>> working on?
>>
>> Leonardo Giordani
>> Author of The Digital Cat <http://lgiordani.github.com>
>> My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
>> page <https://github.com/lgiordani> - My Coderwall 
>> profile<https://coderwall.com/lgiordani>
>>
>>
>> 2013/10/14 Darion Yaphet 
>>
>>>  Python  2.7.3 and Django is 1.5.3 ..
>>>
>>>
>>> 2013/10/14 Leonardo Giordani 
>>>
>>>> Hi, are you using a virtualenv? In that case, can you post the list of
>>>> packages you installed? If not, can you give details about the OS you are
>>>> working on, Django version, and so on?
>>>>
>>>> Regards,
>>>>
>>>> Leo
>>>>
>>>> Leonardo Giordani
>>>> Author of The Digital Cat <http://lgiordani.github.com>
>>>> My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
>>>> page <https://github.com/lgiordani> - My Coderwall 
>>>> profile<https://coderwall.com/lgiordani>
>>>>
>>>>
>>>> 2013/10/14 Darion Yaphet 
>>>>
>>>>> Hi all :
>>>>>
>>>>> when I use django-admin.py to init django project
>>>>> django-admin.py  startproject hello
>>>>>
>>>>> Got a exception ..
>>>>>  AttributeError: 'module' object has no attribute '_handlerList'
>>>>>
>>>>> what is it 
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Django users" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to django-users+unsubscr...@googlegroups.com.
>>>>> To post to this group, send email to django-users@googlegroups.com.
>>>>> Visit this group at http://groups.google.com/group/django-users.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/django-users/a6024b53-9203-4e25-9202-d2cdf017e5a0%40googlegroups.com
>>>>> .
>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Django users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to django-users+unsubscr...@googlegroups.com.
>>>> To post to this group, send email to django-users@googlegroups.com.
>>>> Visit this group at http://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/CAEhE%2BO%3Dr_nPHCA4T3N1hX8--be1R9SMtB%3Deaa_5cFsPCravawg%40mail.gmail.com
>>>> .
>>>>
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>
>>>
>>>
>>> --
>>>
>>>
>>>
>>> long is the way and hard  that out of Hell leads up to light
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAO

Re: def altword_list(self, request, word_id):

2013-10-14 Thread Leonardo Giordani
Can you check the code you posted? The get_query() function is empty so
this code, as posted, can not run.
Please post even the urls you are using to call the view.

Cheers,

Leo

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/15 Pepsodent Cola 

> Hi,
>
> I got some help by somebody on #django IRC.  They gave me this code
> snippet to fix my problem.  But I'm having problems incorporating that code
> into my Class file because Template file says "No list is available" when I
> try to access the list variable.  What am I doing wrong?
>
> # Filter 8
> def altword_list(self, request, word_id):
> #object_list =
> AltWord.objects.filter(word__pk=word_id).order_by('-votes')
> object_list =
> Altword.objects.filter(word__pk=word_id).order_by('-votes')
>
> return render(request, 'navi_polls/altword_list.html', {
> 'poll_list': object_list,
> })
>
>
>
> *Views*
>
> #___
>
> class AltwordlistView(generic.DetailView):
> #model = Word
> model = Altword
> template_name = 'navi_polls/altword_list.html'
> context_object_name = 'poll'
>
> def get_queryset(self):
> # Filter 5
> #return Word.objects.filter(direct_transl_word='')
>
>
> def get_context_data(self, **kwargs):
> context = super(AltwordlistView, self).get_context_data(**kwargs)
> # Filter 4b
> filter_4b =
> Altword.objects.filter(rosword__direct_transl_word='').order_by('-votes')
> # Filter 7
> filter_7 = Altword.objects.vote_order()
> # Filter 8b
> #filter_8b =
> Altword.objects.filter(word__pk=word_id).order_by('-votes')
>
>
> context.update({
> "filter_4b": filter_4b,
> "filter_7": filter_7
>  #   "filter_8b": filter_8b
> })
> return context
>
>
> # Filter 8
> def altword_list(self, request, word_id):
> #object_list =
> AltWord.objects.filter(word__pk=word_id).order_by('-votes')
> object_list =
> Altword.objects.filter(word__pk=word_id).order_by('-votes')
>
> return render(request, 'navi_polls/altword_list.html', {
> 'poll_list': object_list,
> })
>
> #___
> *
> *
>
>
> *Template*
>
> #___
>
> 
> {% if poll_list %}
> 
> {% for row in poll_list %}
> ( id:{{ row.id }} ) - {{ row.rosword }}
> {% endfor %}
> 
> {% else %}
> No list is available.
> {% endif %}
>
>
> 
> 
> 
>
> 
> 
> {% for choice in poll_list %}
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d8f21d91-e06d-428d-923d-08ace9d8df8a%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

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


Re: AttributeError: 'module' object has no attribute '_handlerList'

2013-10-15 Thread Leonardo Giordani
As I suspected, there is a problem with the logging module, which is
probably shadowed, i.e. when Django performs "import logging" it imports a
different module.
Try the following: exactly where you execute the manage.py open an
interactive Python shell and do

>>> import logging
>>> print logging.__file__

This should hopefully show us what logging is working behind the scenes.
Try and post the results

Leo


Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/15 Darion Yaphet 

> the output  exception info as following :
>
> ~ ➤ python /usr/bin/django-admin.py startproject hello --traceback
>
> Traceback (most recent call last):
>   File "/usr/lib/python2.7/site-packages/django/core/management/base.py",
> line 222, in run_from_argv
> self.execute(*args, **options.__dict__)
>File "/usr/lib/python2.7/site-packages/django/core/management/base.py",
> line 255, in execute
> output = self.handle(*args, **options)
>   File
> "/usr/lib/python2.7/site-packages/django/core/management/commands/startproject.py",
> line 31, in handle
> super(Command, self).handle('project', project_name, target, **options)
>   File
> "/usr/lib/python2.7/site-packages/django/core/management/templates.py",
> line 123, in handle
> settings.configure()
>   File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line
> 98, in configure
> self._configure_logging()
>   File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line
> 77, in _configure_logging
> logging_config_func(DEFAULT_LOGGING)
>   File "/usr/lib/python2.7/site-packages/django/utils/dictconfig.py", line
> 555, in dictConfig
> dictConfigClass(config).configure()
>   File "/usr/lib/python2.7/site-packages/django/utils/dictconfig.py", line
> 323, in configure
> del logging._handlerList[:]
> AttributeError: 'module' object has no attribute '_handlerList'
>
> and is  something missing or any package is missing
>
>
> 2013/10/15 Leonardo Giordani 
>
>> Ok, can you please try to traceback the command and post the results?
>>
>> python django-admin.py startproject hello --traceback
>>
>>
>>
>>  Leonardo Giordani
>> Author of The Digital Cat <http://lgiordani.github.com>
>> My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
>> page <https://github.com/lgiordani> - My Coderwall 
>> profile<https://coderwall.com/lgiordani>
>>
>>
>> 2013/10/15 Darion Yaphet 
>>
>>>  ok I built Django 1.5.3  on  fedora 18  and  don't use virtualenv
>>>
>>>
>>> 2013/10/14 Leonardo Giordani 
>>>
>>>> Please give me the information I asked you, otherwise I cannot figure
>>>> out what kind of problem you have.
>>>>
>>>> Are you using a virtualenv? In that case, can you post the list of
>>>> packages you installed? If not, can you give details about the OS you are
>>>> working on?
>>>>
>>>> Leonardo Giordani
>>>> Author of The Digital Cat <http://lgiordani.github.com>
>>>> My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
>>>> page <https://github.com/lgiordani> - My Coderwall 
>>>> profile<https://coderwall.com/lgiordani>
>>>>
>>>>
>>>> 2013/10/14 Darion Yaphet 
>>>>
>>>>>  Python  2.7.3 and Django is 1.5.3 ..
>>>>>
>>>>>
>>>>> 2013/10/14 Leonardo Giordani 
>>>>>
>>>>>> Hi, are you using a virtualenv? In that case, can you post the list
>>>>>> of packages you installed? If not, can you give details about the OS you
>>>>>> are working on, Django version, and so on?
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> Leo
>>>>>>
>>>>>> Leonardo Giordani
>>>>>> Author of The Digital Cat <http://lgiordani.github.com>
>>>>>> My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
>>>>>> page <https://github.com/lgiordani> - My Coderwall 
>>>>>> profile<https://coderwall.com/lgiordani>
>>>>>>
>>>>>>
>>>>>&g

Re: def altword_list(self, request, word_id):

2013-10-16 Thread Leonardo Giordani
Well, I tried to understand the code. Correct me if I did not understand it:

* you are calling AltwordlistView from r'^altword_list/(?P\d+)/$
* being a DetailedView on Altword, AltwordlistView extracts the Altword
with the given pk with a query like Altword.objects.get(pk=pk)
* you set the context you send to the template, in the get_context_data

There, in get_context_data() you have to initialize all the keywords you
are going to use in the template. In this case poll_list.

Note that you define a get_queryset() method in AltwordlistView, but I
think it is not called in a DetailedView, only ListView uses it.

So I'd fix the whole thing this way:

* get rid of get_queryset()
* get rid of the altword_list() function view
* put something like context['poll_list'] =
Altword.objects.filter(word__pk=word_id).order_by('-votes') in
get_context_data()

If you are trying to show a list of objects, however, I suggest you to try
and use a ListView, where you can define your queryset, as you tried to do
with the get_queryset() method.

Try and let me know if something starts to work. Feel free to ask further
if the matter is not clear.

Cheers,

Leo


Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/15 Pepsodent Cola 

>
> Hi Leo,
>
> get_query() function in class AltwordlistView which I refer to as *
> Filter-5* didn't give me the ordered list result that I wanted.  So
> somebody on #django IRC helped me to fix that problem by giving me *
> altword_list()* function which I refer to as *Filter-8*.
> You can basically ignore all the other Filter codes but I left it there in
> case it might help you see what I'm trying to do.
>
> My main focus right now is to connect the Filter-8 code to my template *
> altword_list.html* but I don't know how to do it.
>
> *urls.py*
> http://dpaste.com/1417526/
>
> *views*
> http://dpaste.com/1417533/
>
> *altword_list.html*
> http://dpaste.com/1417534/
>
>
>
>
>
> * urls.py
>
> from django.conf.urls import patterns, urlfrom navi_polls import 
> views#___
> urlpatterns = patterns('',
> # ex: /polls/
> url(r'^$', views.IndexView.as_view(), name='index'),
> # ex: /polls/5/
> url(r'^specifics/(?P\d+)/$', views.DetailView.as_view(), 
> name='detail'),
> # ex: /polls/5/results/
> url(r'^(?P\d+)/results/$', views.ResultsView.as_view(), 
> name='results'),
> # ex: /polls/5/vote/
> url(r'^(?P\d+)/vote/$', views.vote, name='vote'),
>
> # ex: /polls/5/
> url(r'^altword_list/(?P\d+)/$', views.AltwordlistView.as_view(), 
> name='altword_list'),)
>
>
>
>
> * views.py
>
> from django.http import HttpResponseRedirectfrom django.shortcuts import 
> render, get_object_or_404from django.core.urlresolvers import reversefrom 
> django.views import genericfrom django.utils import timezone
> from navi_polls.models import Word, 
> Altword#___
> class IndexView(generic.ListView):
> template_name = 'navi_polls/index.html'
> context_object_name = 'latest_poll_list'
>
> def get_queryset(self):# Filter 1
> """Return the last five published polls(not including 
> those set to be published in the future)."""
> return Word.objects.filter(pub_date__lte=timezone.now()
> ).order_by('-pub_date')[:5]
>
> #"""
> #Return the last five published polls
> #(including those set to be published in the future).
> #"""
> #return Word.objects.order_by('-pub_date')[:5]
>
>
> def get_context_data(self, **kwargs):
> context = super(IndexView, self).get_context_data(**kwargs)# Filter 2
> filter_2 = Word.objects.filter(direct_transl_word='')# Filter 4
> filter_4 = Altword.objects.filter(rosword__direct_transl_word='')
>
> context.update({
> "filter_2": filter_2,
> "filter_4": filter_4
> })
> return 
> context#___
>
>
> #___
> class Al

Re: How to handle values_list?

2013-10-17 Thread Leonardo Giordani
Andrew, I think that the view is missing something:

def enter_name(request):

my_number = request.user.number

name = Name.objects.filter(pk=my_number).values_list('city', flat=True)

*data = {...}
*

*return render_to_response('template.html', data,
context_instance=RequestContext(request))*


where data is a dictionary with the values you want to be available in your
template. So, for the template you posted, you could write


data = {'name':name[0]}


Here, you need to decide what you need to pass: why do you use filter()
instead of get()? Do you need just one value or multiple?

If you need to pass a list to the template just fill the dictionary
accordingly, but follow Daniel's advice when rendering the list in the
template.


Regards,


Leo



Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/17 Charly Román 

> Have you tried used get instead filter?
>
> 2013/10/17 Daniel Roseman :
> > On Thursday, 17 October 2013 19:30:09 UTC+1, Andrew Michael wrote:
> >>
> >> Hi,
> >>
> >> I am new to Django and need some help. My issue is on my web page the
> data
> >> is showing up like this: [u'Green'] and I want it to only show Green -
> >> without the unicode wrapping. Can you please explain why this is
> happening
> >> and how do I fix it?
> >>
> >> Here is my code.
> >>
> >> models.py:
> >>
> >> Class Name(models.Model):
> >>
> >> name = models.CharField(_('name'), max_length=100)
> >>
> >> number = models.ForeignKey(Number)
> >>
> >> views.py:
> >>
> >> def enter_name(request):
> >>
> >> my_number = request.user.number
> >>
> >> name = Name.objects.filter(pk=my_number).values_list('city',
> >> flat=True)
> >>
> >> template.html:
> >>
> >> {{ name|safe }}
> >>
> >>
> >>
> >> Prints on the web page:
> >>
> >> [u’Green’]
> >
> >
> > This nothing to do with Unicode. `name` is a *list*. So you have to
> iterate
> > over it:
> >
> > {% for name in names %}
> > {{ name }}
> > {% endfor %}
> > --
> > DR.
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to django-users+unsubscr...@googlegroups.com.
> > To post to this group, send email to django-users@googlegroups.com.
> > Visit this group at http://groups.google.com/group/django-users.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/django-users/f1d664fc-4a67-4d1f-8df5-76fda1bbef20%40googlegroups.com
> .
> >
> > For more options, visit https://groups.google.com/groups/opt_out.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABeWMUbaxazs1Sh0GMLhJVSXGcieUsTBhz2AgbWrhWD%2BBwru%3DQ%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

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


Re: set-up and usage of mysql in django

2013-10-20 Thread Leonardo Giordani
What is your exact problem?

If you need to use a MySQL server you just need to put the server address
and credentials in your settings.py file, then run manage.py syncdb, just
like you do with the development server. Everything you did in the tutorial
(you did it, right?) is still valid, thanks to the layer called ORM, which
maps the DB to Python objects.

As for the management you can issue standard SQL commands through the mysql
command line tool. I suggest you to use Fabric (
http://docs.fabfile.org/en/1.8/) to automate the process.

Feel free to post a more detailed question.
Cheers,

Leo

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/21 Mahantesh U 

> Pls let me know how to use mysql with django with few examples... I'm new
> to django.
>
> Thanks
> mahantesh
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a6eb46a0-55f5-4328-b46a-db2a577a55dd%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BO%3DSwXxrn-AvWAwzyL_877mPOJKEXSSdoyDR0acepTtOKQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Customizing your project's templates

2013-10-21 Thread Leonardo Giordani
I think that you are missing the absolute path part of the code comment

*# Don't forget to use absolute paths, not relative paths.

*
This means that you cannot use 'lotus/...'
Usually you use code like

ABSOLUTE_PATH = '%s/'
%(os.path.abspath(os.path.dirname(locals()['__file__'])).replace('\\', '/'))

at the beginning of your settings.py file. Then you can write

TEMPLATE_DIRS = (
*os.path.join(ABSOLUTE_PATH, 'lotus/pollapp/mysite/polls/**templates'),*
# Put strings here, like "/home/html/django_templates" or
"C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)

Remember that settings.py is a Python module, so you can use any valid
Python code.

Let me know if you succeed.
Cheers,

Leo


Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/21 Sheharyar Hamayun 

> Ok, so i've copied the *base_site html* 
> to*lotus/pollapp/mysite/polls/templates/admin
> * . I've opened the html file in a text editor and changed
>
> * {% trans 'Django administration' %}*   to
>
> *{% trans 'Pollapp' %}*
>
> However this change doesn't show on the website. My *Template DIRS* is:
>
> TEMPLATE_DIRS = (
> *'lotus/pollapp/mysite/polls/templates',*
> # Put strings here, like "/home/html/django_templates" or
> "C:/www/django/templates".
> # Always use forward slashes, even on Windows.
> # Don't forget to use absolute paths, not relative paths.
> )
>
> I've restarted the dev server and refreshed the website many times, but
> still no change.
> Any help with what i'm doing wrong?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5fb2f9b7-8340-4be4-8ba9-cfd8536404a9%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

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


Re: variable in django template

2013-10-23 Thread Leonardo Giordani
Hi,

everything you need in a template can be prepared in a view, so if you need
a specific value just pass a context key with that very value.
Otherwise, if you need a list of integers, just pass a range(N) list.
There is a plenty of builtin filters and tags you can then use to manage it.

If you can better clarify what you want to accomplish, I can perhaps be
more specific.

Regards,
Leo

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/23 Harjot Mann 

> I want to initialize a varibale in django template from zero, which I
> want to comapre with the some job_no whihc is coming from database. I
> am not getting hoe to decalre a variable. Please help me .
> --
> Harjot Kaur Mann
> Blog: http://harjotmann.wordpress.com/
> Daily Dairy: http://harjotmann.wordpress.com/daily-diary/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAB0GQhBfRf3cK-YZ1R90rNaKWgUunVZ_R_nxynSD8LuXQOGoWQ%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BOkjYLnWrfPG6eyN1OC-iRtRnipsV8XiNyow6jREiy5fPQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: variable in django template

2013-10-23 Thread Leonardo Giordani
Indeed this is a good solution. Just a typo correction, use "%" instead of
"@".

Leo

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/23 Nicolas Pantel 

> Take a look at the "{@ with @}" template tag in the documentation. Use {@
> with myVariable=someValue @} ... {@ endwith @}.
>
> NicoP
>
> Le 23 oct. 2013 07:01, "Harjot Mann"  a écrit :
>
> >
> > I want to initialize a varibale in django template from zero, which I
> > want to comapre with the some job_no whihc is coming from database. I
> > am not getting hoe to decalre a variable. Please help me .
> > --
> > Harjot Kaur Mann
> > Blog: http://harjotmann.wordpress.com/
> > Daily Dairy: http://harjotmann.wordpress.com/daily-diary/
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Django users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscr...@googlegroups.com.
> > To post to this group, send email to django-users@googlegroups.com.
> > Visit this group at http://groups.google.com/group/django-users.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAB0GQhBfRf3cK-YZ1R90rNaKWgUunVZ_R_nxynSD8LuXQOGoWQ%40mail.gmail.com
> .
> > For more options, visit https://groups.google.com/groups/opt_out.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAE9byzDNxxzrvCtF16OE%2B1GOOdHw7WQUjmdFEuEinp_Qonj%3DQw%40mail.gmail.com
> .
>
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BOmSDTDBkE19H4EV4hv6pd%3Dsx2CcdWGLcoqOBmoSeeBTnw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: formating

2013-10-28 Thread Leonardo Giordani
I think that the extra space between "floatformat:" and "2" is confusing
the template system. Try using "floatformat:2" without spaces.

Leo

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/26 fabricio mata 

> even through the code {{form.valor_ultimacompra | floatformat: 2}} does
> not return anything.
>
> my model is
>
> valor_ultimacompra = models.DecimalField (u'Vlr. Ult.Compra 'max_digits =
> 18, decimal_places = 2, default = 0, blank = True, null = True)
>
>
> when you step this way}} {{form.valor_ultimacompra works
>
>
> can someone ajuadar me?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/abddc39f-4379-4ecf-88bc-c178d895ea50%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BOm1k%3DOTBZtC2VQtydOnnrgZ0Ao-%2BYV23TLQ_Wo3%2BvQxQg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Digging up Django class-based views - 1

2013-10-28 Thread Leonardo Giordani
Hi all,

I want to share with you a post about class-based views.
Hope you find it useful.

http://lgiordani.github.io/blog/2013/10/28/digging-up-django-class-based-views-1/


Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BOmuYpOYsEbHKfafJr_7XzTAhYBO794AfV0M%2BJ1jELBpmA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: formating

2013-10-28 Thread Leonardo Giordani
Can you please paste the code with a good formatting? To pastebin or
similar?
I'd like to see model, view and template.


Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/28 fabricio 

>
> does not work
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/6af0e106-ce9a-47c9-87d6-6a35e8e486fa%40googlegroups.com
> .
>
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BOnL4bg4%3D%2BqUvckWTKoGzqXQg1TLjJRr%2BGBMEq%3Drhu%3DHBg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: formating

2013-10-28 Thread Leonardo Giordani
What is foundation?
You said that

{{form.valor_ultimacompra}}

works. What about

{{form.valor_ultimacompra|foundation}}

?


Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/28 fabricio 

>
> no meu modelo
> valor_ultimacompra = models.DecimalField(u'Vlr.Ult.Compra', max_digits=18,
> decimal_places=2, default=0, blank=True, null=True)
>
>
> no template
> {% extends "base.html" %}
> {% load humanize %}
> {% load foundation %}
>
>
> 
> {{form.valor_ultimacompra|foundation| floatformat:2 }}
> 
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/9168889e-0227-4387-8dc1-fe434fecd1a1%40googlegroups.com
> .
>
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BOn7V4K2enL2TiGX7%2ByNv4__JzTPfQ2uCEzn1W%2BfSpaWqw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Digging up Django class-based views - 1

2013-10-29 Thread Leonardo Giordani
Thank you! I am going to correct it asap.

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/10/29 Tom Evans 

> On Mon, Oct 28, 2013 at 8:01 AM, Leonardo Giordani
>  wrote:
> > Hi all,
> >
> > I want to share with you a post about class-based views.
> > Hope you find it useful.
> >
> >
> http://lgiordani.github.io/blog/2013/10/28/digging-up-django-class-based-views-1/
> >
>
> Nice - clearly written. You have a couple of typos in your code blocks
> in the "URL Dispatchers and views" section, **kwds instead of **kwargs
> as in the method definition.
>
> Cheers
>
> Tom
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAFHbX1JCVyoocEqreOeOSWzxZUiY3e7Xb4WEQr0VBr_SgLg5Ew%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BOkwmodjrysxrj-t-jo8s6%2BnV4Rvgve_7ObttN54GkEM%3DQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re:

2013-11-04 Thread Leonardo Giordani
Hi,

please include the relevant part of the models and the views when asking
such questions, otherwise it is very difficult for people to help you.

I'd say that the problem is in the query extracting the values you are
showing. You say you do not want number 22 to appear twice: if  there are
two entries with the same number it is clearly not a primary key, so
probably you are filtering on the wrong column.

Leo

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/11/1 Harjot Mann 

> The following picture is displaying is showing the html template
> results in which it is shown that the number 22 repeats two times and
> it is having separate ref numbers, and I want that the repeated values
> should not appear twice.
> ex: some amount line 5301 is appearing in both but i dnt need it, I
> only need it once.
> any idea how to do it?
>
>
> http://202.164.53.122/~harjotmann/errors/susreg.png
>
> --
> Harjot Kaur Mann
> Blog: http://harjotmann.wordpress.com/
> Daily Dairy: http://harjotmann.wordpress.com/daily-diary/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAB0GQhBLO75C3KF-g0QVxzh2wWUbnqmJ6VmZvEFp%3DyY9ur2FaQ%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BO%3Ddu1b8T61ToJZNgnYzM7vBpNXqH82cVD%3DfdxT0qgTLTw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: TypeError: can't subtract offset-naive and offset-aware datetimes

2013-11-04 Thread Leonardo Giordani
Take a look at

https://docs.djangoproject.com/en/dev/topics/i18n/timezones/#naive-and-aware-datetime-objects

Basically you need to fix datetime objects adding a timezone.

Regards,

Leo

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/11/4 NHT 

> In poll app, I set Time_Zone='Asia/Kolkata' and USE_TZ=True in settings.py
> file.
> In models.py file,
>
> import datetime
> from django.utils import timezone
> from django.db import models
>
> class Poll(models.Model):
> question = models.CharField(max_length=200)
> pub_date = models.DateTimeField('date published')
> def __unicode__(self):
> return self.question
> def was_published_recently(self):
> return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
>
> class Choice(models.Model):
> poll = models.ForeignKey(Poll)
> choice_text = models.CharField(max_length=200)
> votes = models.IntegerField(default=0)
> def __unicode__(self):
> return self.choice_text
>
> when I try to run this code , I am getting the above error.I am using
> Windows 8. Please help!!
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/979241e3-43ab-41fb-9148-4a3fd9022c15%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

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


Re: Error while deploying django with mod wsgi

2013-11-18 Thread Leonardo Giordani
Hi Sebastian,

it seems that you are experiencing a name clash or similar.
email.quoprimime is included in Python 2.6 (see here
http://hg.python.org/cpython/file/3edf679917ba/Lib/email) so if you find it
in /usr/lib/python2.6/email/quoprimime.py then you are probably masking the
name "email" with something different, perhaps a local Python file.

Moreover, you say that you are using a virtual environment, but your
traceback refers to /usr/lib/python2.6, so I think that something there is
not working as you expected too.
May you check your paths? How are you running the deployed package?

Let me know, cheers

Leo


Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/11/18 Sebastian Clemens 

> Hello,
>
> here's my traceback, I use a virtualenv running django.
>
> [Mon Nov 18 17:40:03 2013] [error] [client 79.205.192.140] ServerName: '
>> sebastian-clemens.de'
>> [Mon Nov 18 17:40:03 2013] [error] [client 79.205.192.140] DocumentRoot:
>> '/var/www/vhosts/sebastian-clemens.de/httpdocs'
>> [Mon Nov 18 17:40:03 2013] [error] [client 79.205.192.140] URI: '/'
>> [Mon Nov 18 17:40:03 2013] [error] [client 79.205.192.140] Location: None
>> [Mon Nov 18 17:40:03 2013] [error] [client 79.205.192.140] Directory:
>> '/var/www/vhosts/sebastian-clemens.de/httpdocs/'
>> [Mon Nov 18 17:40:03 2013] [error] [client 79.205.192.140] Filename:
>> '/var/www/vhosts/sebastian-clemens.de/httpdocs/wsgi.py'
>> [Mon Nov 18 17:40:03 2013] [error] [client 79.205.192.140] PathInfo: '/'
>> [Mon Nov 18 17:40:03 2013] [error] [client 79.205.192.140] Traceback
>> (most recent call last):
>> [Mon Nov 18 17:40:03 2013] [error] [client 79.205.192.140] File
>> "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1537, in
>> HandlerDispatch\n default=default_handler, arg=req, silent=hlist.silent)
>> [Mon Nov 18 17:40:03 2013] [error] [client 79.205.192.140] File
>> "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1229, in
>> _process_target\n result = _execute_target(config, req, object, arg)
>> [Mon Nov 18 17:40:03 2013] [error] [client 79.205.192.140] File
>> "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1128, in
>> _execute_target\n result = object(arg)
>> [Mon Nov 18 17:40:03 2013] [error] [client 79.205.192.140] File
>> "/usr/lib/python2.6/dist-packages/mod_python/cgihandler.py", line 96, in
>> handler\n imp.load_module(module_name, fd, path, desc)
>> [Mon Nov 18 17:40:03 2013] [error] [client 79.205.192.140] File
>> "/var/www/vhosts/sebastian-clemens.de/httpdocs/wsgi.py", line 12, in
>> \n from django.core.wsgi import get_wsgi_application
>> [Mon Nov 18 17:40:03 2013] [error] [client 79.205.192.140] File
>> "/var/www/vhosts/
>> sebastian-clemens.de/httpdocs/lib/python2.6/site-packages/django/core/wsgi.py",
>> line 1, in \n from django.core.handlers.wsgi import WSGIHandler
>> [Mon Nov 18 17:40:03 2013] [error] [client 79.205.192.140] File
>> "/var/www/vhosts/
>> sebastian-clemens.de/httpdocs/lib/python2.6/site-packages/django/core/handlers/wsgi.py",
>> line 9, in \n from django import http
>> [Mon Nov 18 17:40:03 2013] [error] [client 79.205.192.140] File
>> "/var/www/vhosts/
>> sebastian-clemens.de/httpdocs/lib/python2.6/site-packages/django/http/__init__.py",
>> line 4, in \n from django.http.response import (HttpResponse,
>> StreamingHttpResponse,
>> [Mon Nov 18 17:40:03 2013] [error] [client 79.205.192.140] File
>> "/var/www/vhosts/
>> sebastian-clemens.de/httpdocs/lib/python2.6/site-packages/django/http/response.py",
>> line 6, in \n from email.header import Header
>> [Mon Nov 18 17:40:03 2013] [error] [client 79.205.192.140] File
>> "/usr/lib/python2.6/email/header.py", line 53, in \n _max_append =
>> email.quoprimime._max_append
>> [Mon Nov 18 17:40:03 2013] [error] [client 79.205.192.140]
>> AttributeError: 'module' object has no attribute 'quoprimime'
>
>
> What can I do to solve "AttributeError: 'module' object has no attribute
> 'quoprimime'" ?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send 

Re: order_by result of sum of fields computed from an annotate

2013-11-18 Thread Leonardo Giordani
May you please post the code of Book and Author models? Thanks


Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/11/16 J. C. Leitão 

> Hi there.
>
> Consider the situation where you want to order_by a sum of two fields
> obtained from an annotation. This 
> problem<http://stackoverflow.com/questions/4899014/using-extra-on-fields-created-by-annotate-in-django>
>  states
> it correctly, however, the solution is not working for me.
>
> For concreteness, consider the example:
>
> Author.objects.annotate(first_date=Avg('all_books__published_date'),
>last_date=Avg('all_books__added_date'))\
>  .extra(select = {'delta_time': 'last_date -
> first_date'},
>   order_by=['-delta_time'])
>
> Where:
>
> - Book has a manyToMany relationship with Author and 'all_books' is the
> related_name from the book to the author.
> - *_date are dates.
>
> I.e. For each author, I'm computing the average time it takes for a book
> to be added (e.g. to a library) since the moment it was published.
>
> This query is not correct as "(1054, "Unknown column 'last_date' in 'field
> list'")", which I suspect is because the field all_books is a ManyToMany.
>
> The 
> solution<http://stackoverflow.com/questions/4899014/using-extra-on-fields-created-by-annotate-in-django>
>  I
> found so far was an extra like this:
>
> Author.objects.extra(
> select = {'delta_time': 'AVG(all_books__added_date) -
> AVG(all_books__published_date)'},
> order_by = ['-delta_time']
> )
>
> but in this case this is not working with the error ""Unknown column
> 'all_books__added_date'", which I suspect is also because the field is a
> ManyToMany.
>
> Any ideas on how to create this query?
>
> Thanks,
> Jorge
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/104ab2a3-17e7-4726-be87-0ac353d957ca%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BOk4ey8b3Opt32K082r%3Drr%2BFnH0Ne4QnyCUxRiB7dgW9Wg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: votes/score

2013-11-18 Thread Leonardo Giordani
Érico,

it is not really clear to me what you are trying to accomplish. That HTML
in MYVALUES is a try to show that line in the dropdown? And why is
"{{form|safe}}" there?
May you please decribe what you would like to obtain?

Cheers,

Leo



Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/11/14 Érico Oliveira 

> Hy, i'm learning django.
> My idea is to give marks / votes for a selected job.
> Works but not as I would.
>
> class Job(models.Model):
> title= models.CharField(max_length=20)
> slug = models.SlugField(max_length=40, blank=True)
> def __unicode__(self):
> return self.title
>
>
> class Vote(models.Model):
> job = models.ForeignKey(Job)
> score = models.IntegerField(blank=True, default=0)
>
>
> my forms.py
>
> MYVALUES = (
> (5, u'5 '), # don't work {{
> form|safe }}
> (5, five'),
> (3, u'three'),
> (2, u'two'),
> (1, u'one'),
> )
> class FormVote(forms.ModelForm):
> class Meta:
> model = Vote
> score = forms.ChoiceField(choices=MYVALUES, widget=forms.RadioSelect())
>
>
> <https://lh6.googleusercontent.com/-QVtgBBK6iqM/UoUD41aFDRI/Abw/FP4erR2SEu4/s1600/form_2.png>
>
> As I did all the html / css. I would not return the form that way.
> I tried a different approach, trying to pass the values of the vote
> through a link using jquery, but I can not mount the garvar to view the
> value of voting.
>
> It would be a mess trying to return an HTML inside FormVote, something
> like:
>
>
>
> <https://lh3.googleusercontent.com/-8ES0mhP_mHs/UoUD9G_57JI/Ab4/m_S82B097W4/s1600/votes.png>
>
>
>
>
> Help?
> thanks in advance.
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/736728d8-dc12-41aa-b223-7c8bed0a2cf4%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BOnEAsC_HKNHpHd9-%2BTbfbo0MogSN0R%3DztN_N2DC73W2fA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: order_by result of sum of fields computed from an annotate

2013-11-19 Thread Leonardo Giordani
Well, indeed the matter is not simple =)

I looked at the raw SQL for your queries and the results are the following
(just print queryset.query to show SQL).

The SQL query for

Author.objects.extra(select={'average_delay':
"Avg('all_books__published_date')-Avg('all_books__added_date')"})

is

SELECT (Avg('all_books__published_date')-Avg('all_books__added_date')) AS
"average_delay", "prova_author"."id", "prova_author"."name" FROM
"prova_author"

so you see that it cannot work, as you stated. Django does not recognize
that extra is working on a joined table, and this because the string passed
to select in extra are unparsed. Documentation states that "Django inserts
the given SQL snippet directly into the SELECT statement".

The other solution you tried is

Author.objects.annotate(first_date=Avg('all_books__published_date'),
last_date=Avg('all_books__added_date')).extra(select={'average_delay':
"last_date - first_date"})

that produces the following SQL

SELECT (last_date - first_date) AS "average_delay", "prova_author"."id",
"prova_author"."name", AVG("prova_book"."added_date") AS "last_date",
AVG("prova_book"."published_date") AS "first_date" FROM "prova_author" LEFT
OUTER JOIN "prova_book_authors" ON ("prova_author"."id" =
"prova_book_authors"."author_id") LEFT OUTER JOIN "prova_book" ON
("prova_book_authors"."book_id" = "prova_book"."id") GROUP BY
"prova_author"."id", "prova_author"."name", (last_date - first_date)

If I correctly remember SQL (not my forte) you cannot refer in the SELECT
clause to aliases that you define in the SELECT itself.

There is some onging work in Django to allow F() objects in annotations so
this perhaps will solve such issues.

Until then I'd suggest you to do the following: the difference of averages
is the average of the differences (in this case, since the number of object
is the same for the first and the second average), so you can store in your
object the difference between published and insertion date, overriding the
save() method. Then you annotate and filter on the Avg() of this new field.

Try and let me know if it works. Regards

Leo





Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/11/19 Jorge Cardoso Leitão 

> I'm sorry, you are right, I should have provided them. Let me formulate
> the question again, but with a complete example.
>
> # models.py
>
> class Book(models.Model):
> added_date = models.DateField()# date it was added to my shelf
> published_date = models.DateField()  # date it was published
>
> authors = models.ManyToManyField('Author', related_name='all_books')
>  # a book can have more than 1 author
>
>
> class Author(models.Model):
> name = models.CharField(max_length=100)
>
> #fixture.json
>
> [
> {
> "model": "main.Author",
> "pk": 1,
> "fields": {
> "name": "John 1"
> }
> },
> {
> "model": "main.Author",
> "pk": 2,
> "fields": {
> "name": "John 2"
> }
> },
> {
> "model": "main.Book",
> "pk": 1,
> "fields": {
> "added_date": "2000-01-01",
> "published_date": "1999-12-31",
> "authors": [1]
> }
> },
> {
> "model": "main.Book",
> "pk": 1,
> "fields": {
> "added_date": "2000-01-02",
> "published_date": "1999-12-31",
> "authors": [1, 2]
> }
> }
> ]
>
> Notice that book 1 has 1 author, and it took 1 day to add to the shelf.
> Book 2 has 2 authors, and took 2 days to add.
>
> The average delay between publishing and adding is thus, for each author,
>
> John 1: 1.5 days  # (1 day + 2 days)/2
> John 2: 1 day.
>
> I'm trying to query authors with the average delay annotated, and ordered
> by it.
>
> Notice that the

Re: Filtering by month doesn't work

2013-11-25 Thread Leonardo Giordani
May you please post your Event model?

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/11/26 Начаров Михаил 

> Hi Tranta.
> In my projects this functionality works fine.
> What version of django did you used?
> Do you sure that field end in Event table contains November dates?
>
> Also, you can use *today.month* instead of  *int(today.strftime('%m')*)
> and* today.year *instead of  *int(today.strftime('%Y')).*
> And in django docs says that it necessary to validate your form before use
> it:
>
> *if event_form.is_valid():*
> *event = event_form.save()*
>
>
> вторник, 26 ноября 2013 г., 5:24:21 UTC+6 пользователь Vojtěch Tranta
> написал:
>
>> Hi,
>> do you have any clue why this does not work?
>>
>> def index(request):
>> if request.method == 'POST' and request.POST:
>> event_form = EventForm(request.POST)
>> event = event_form.save()
>>
>> today = datetime.date.today();
>> year = int(today.strftime('%Y'))
>> month = int(today.strftime('%m'))
>> events = Event.objects.filter(end__month='11')
>> # events = Event.objects.all()
>> pdb.set_trace()
>> cal = jvccalendar.HTMLCalendar(jvccalendar.MONDAY).formatmonth(year,
>> month, events)
>> form = EventForm()
>> return render_to_response('jvc/index.html', {'cal': cal, 'side_form':
>> form}, context_instance=RequestContext(request))
>>
>>
>> I am still getting "events" as empty, filtering using
>> filter(end_start='2013') works, but filtering by month does not, I googled
>> as much as I could, but no luck. I copied code from StackOverflow, but no
>> luck
>> Thank you!
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4521ed83-d85b-42a5-a344-27ac273648b9%40googlegroups.com
> .
>
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BOmKTMpq8x%3DpZSHqrSDa_HS3z%2BYhaz%2BVsa1JZ9%3DFpOrPYQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Filtering by month doesn't work

2013-11-26 Thread Leonardo Giordani
Are you sure that filtering using a string is the same as filtering using
an int? I think that Django doesn't automatically convert it. So the
condition

events = Event.objects.filter(end__month='11')

should be

events = Event.objects.filter(end__month=11)

Indeed 
documentation<https://docs.djangoproject.com/en/dev/ref/models/querysets/#year>does
things this way. I see that you succeded in filtering with

filter(end_start='2013')

perhaps end__startswith? In that case you are treating it as a string.
May you please check this and let me know?

Cheers,

Leo



Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2013/11/26 Vojtěch Tranta 

> from django.db import models
> from django.contrib.auth.models import User
> from student import Student
> from eventtype import EventType
> from django import forms
> import datetime
>
> class Event(models.Model):
> user = models.ForeignKey(User)
> student = models.ForeignKey(Student)
> place = models.CharField(max_length=200, null=True)
> type = models.ForeignKey(EventType)
> start = models.DateTimeField('event start', default=datetime.datetime.now)
> end = models.DateTimeField('event end', default=datetime.datetime.now)
> absence = models.NullBooleanField()
> note = models.TextField(null=True)
> created = models.DateTimeField('created time')
> created_by = models.ForeignKey(User, related_name='event creator')
> description = models.TextField(null=True)
>
> class Meta:
> app_label = 'jvc'
>
> def __unicode__(self):
> return self.type.name +' '+ self.student.fullname +'
> '+self.start.strftime('%d.%m.%Y')
>
> I should mention that I have my models in separated files in "models"
> folder inside app called "jvc"
>
> Dne úterý, 26. listopadu 2013 8:25:40 UTC+1 Leo napsal(a):
>>
>> May you please post your Event model?
>>
>> Leonardo Giordani
>> Author of The Digital 
>> Cat<http://www.google.com/url?q=http%3A%2F%2Flgiordani.github.com&sa=D&sntz=1&usg=AFQjCNGf6sQVThK6cSl7xZSyl-Bug05qnQ>
>> My profile on 
>> About.me<http://www.google.com/url?q=http%3A%2F%2Fabout.me%2Fleonardo.giordani&sa=D&sntz=1&usg=AFQjCNENNv2kLwQkkcUqNGwAk9LiXuqX-g>-
>>  My GitHub
>> page<https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Flgiordani&sa=D&sntz=1&usg=AFQjCNEkP_q2HuIVZV_RDYFkz6AxG6GeqA>-
>>  My Coderwall
>> profile<https://www.google.com/url?q=https%3A%2F%2Fcoderwall.com%2Flgiordani&sa=D&sntz=1&usg=AFQjCNHxgTeAYqzzxvSU2GFb7dMA1APtEA>
>>
>>
>> 2013/11/26 Начаров Михаил 
>>
>>> Hi Tranta.
>>> In my projects this functionality works fine.
>>> What version of django did you used?
>>> Do you sure that field end in Event table contains November dates?
>>>
>>> Also, you can use *today.month* instead of  *int(today.strftime('%m')*)
>>> and* today.year *instead of  *int(today.strftime('%Y')).*
>>> And in django docs says that it necessary to validate your form before
>>> use it:
>>>
>>> *if event_form.is_valid():*
>>> *event = event_form.save()*
>>>
>>>
>>> вторник, 26 ноября 2013 г., 5:24:21 UTC+6 пользователь Vojtěch Tranta
>>> написал:
>>>
>>>> Hi,
>>>> do you have any clue why this does not work?
>>>>
>>>> def index(request):
>>>> if request.method == 'POST' and request.POST:
>>>>  event_form = EventForm(request.POST)
>>>> event = event_form.save()
>>>>
>>>> today = datetime.date.today();
>>>>  year = int(today.strftime('%Y'))
>>>> month = int(today.strftime('%m'))
>>>> events = Event.objects.filter(end__month='11')
>>>>  # events = Event.objects.all()
>>>> pdb.set_trace()
>>>> cal = jvccalendar.HTMLCalendar(jvccalendar.MONDAY).formatmonth(year,
>>>> month, events)
>>>>  form = EventForm()
>>>> return render_to_response('jvc/index.html', {'cal': cal, 'side_form':
>>>> form}, context_instance=RequestContext(request))
>>>>
>>>>
>>>> I am still getting "events" as empty, filtering using
>>>> filter(end_start='2013') works, but filtering by month does not, I g

Digging Up Django Class-based Views

2014-02-14 Thread Leonardo Giordani
Hi all,

the third issue of the small series "Digging Up Django Class-based Views"
is out.
This latest post is about form views.

You find the whole series here

http://lgiordani.github.io/blog/categories/django/

I hope you will find it interesting and useful.

Cheers,

Leo


Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BO%3Db8ApXRSwLEmMXf%3D_XMtRDv78uZO-SMr1jzcUQuYsqjw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Digging Up Django Class-based Views

2014-02-17 Thread Leonardo Giordani
You are welcome! I'm glad to know that it was useful. I hope to post soon
some tips with real world examples.

Cheers,

Leo

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2014-02-17 5:23 GMT+01:00 Frankline :

> Hi Leo,
>
> I have struggled to understand CBVs before and avoided using them most of
> the time. I looked into your posts and it has been very useful. Written in
> clear simple English. Now I can't wait to use them in my current and next
> projects.
>
> :-)
>
> Thank you.
>
> Frank
>
>
> On Fri, Feb 14, 2014 at 4:11 PM, Leonardo Giordani <
> giordani.leona...@gmail.com> wrote:
>
>> Hi all,
>>
>> the third issue of the small series "Digging Up Django Class-based Views"
>> is out.
>> This latest post is about form views.
>>
>> You find the whole series here
>>
>> http://lgiordani.github.io/blog/categories/django/
>>
>> I hope you will find it interesting and useful.
>>
>> Cheers,
>>
>> Leo
>>
>>
>> Leonardo Giordani
>> Author of The Digital Cat <http://lgiordani.github.com>
>> My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
>> page <https://github.com/lgiordani> - My Coderwall 
>> profile<https://coderwall.com/lgiordani>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAEhE%2BO%3Db8ApXRSwLEmMXf%3D_XMtRDv78uZO-SMr1jzcUQuYsqjw%40mail.gmail.com
>> .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAEAUGdWD2mHe3R50TXXwXe5qGOgWwvZaROde3TmViXw4%2B%3DF2hg%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BOnMwO-QK2STtSd5w4sMRmsmvE7fUjSFvbM7i2ynyeMecw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: OneToOne? Inheritance? Another solution for nested model relationships?

2014-05-28 Thread Leonardo Giordani
Daniele,

I usually solve such issues with Inheritance. I feel comfortable with it
because it lets me (in your example) to manage both ResearchStudent and
ResearchStaff independently, while keeping the Researcher parent model
available to deal with "global" queries and data interaction.

As always with inheritance, I suggest to think twice before implementing
it, but in this case I'd say that it fits perfectly.


Regards,

Leo

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2014-05-26 23:33 GMT+02:00 Daniele Procida :

> I've an application that's been happily running for a few years, that does
> this:
>
> class Person(Model):
># everyone's a Person
>
> class Researcher(Model):
> # a Researcher is Person who publishes research
> person = models.OneToOneField(Person)
>
> class Publication(Model):
> author = models.ForeignKey(Researcher)
>
>
> But this is no longer enough: now I also need to distinguish between
> Researchers who are research students and members of staff. Those who are
> students will need new fields such as "thesis_title" and "supervisors".
>
> But, I will *still* need the Researcher class independently of the new
> ResearchStudent and ResearchStaff classes, because it's needed for
> Publication.author.
>
> So now it might look something like this:
>
> class Person(Model):
># everyone's a Person
>
> class Researcher(Model):
> # a Researcher is Person who publishes research
> person = models.OneToOneField(Person)
>
> class ResearchStaff(Model):
>researcher = models.OneToOneField(Researcher)
>
> class ResearchStudent(Model):
>researcher = models.OneToOneField(Researcher)
>supervisors = models.ManyToManyField(ResearchStaff)
>
> class Publication(Model):
> author = models.ForeignKey(Researcher)
>
>
> How manageable is this going to be? Is there a better way of doing what I
> need to do, perhaps through inheritance?
>
> Thanks,
>
> Daniele
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/20140526213320.1042853662%40mail.wservices.ch
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BOkbUadKLYPqjqqLFAkdrBY86Lyjv_AoYG%3Dd8fY6A6WdnQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django get queryset year month day

2014-05-28 Thread Leonardo Giordani
If I correctly understand you issue is to get part of the date for each
item in a list of datetime.datetime or datetime.date objects.
To do this you can process the list after the query

new_list = [item.year for item in item]

But if your need is to extract fields from the objects in the result list
you may use 
values()<https://docs.djangoproject.com/en/1.2/ref/models/querysets/#values>or
values_list()<https://docs.djangoproject.com/en/1.2/ref/models/querysets/#values-list>
.

Let me know if this answers your question.

Regards,

Leo



Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub
page<https://github.com/lgiordani>- My Coderwall
profile <https://coderwall.com/lgiordani>


2014-05-27 12:40 GMT+02:00 Helton Alves :

> Hi guy.
> so, A don't is understand very well.
>
> but the django has the generic date views, I think is exactly this.
>
>
> https://docs.djangoproject.com/en/dev/ref/class-based-views/generic-date-based/#module-django.views.generic.dates
>
>
>
>
> 2014-05-27 9:06 GMT+01:00 hito koto :
>
> Hi,
>>
>> I want to get only year and get only month,
>> i want to get the only : 2005  and  05-27
>> How can i to do?
>>
>> I know this :
>>
>> >>> Entry.objects.dates('pub_date', 'year')[datetime.date(2005, 1, 1)]>>> 
>> >>> Entry.objects.dates('pub_date', 'month')[datetime.date(2005, 2, 1), 
>> >>> datetime.date(2005, 3, 1)]>>> Entry.objects.dates('pub_date', 
>> >>> 'day')[datetime.date(2005, 2, 20), datetime.date(2005, 3, 20)]>>> 
>> >>> Entry.objects.dates('pub_date', 'day', order='DESC')[datetime.date(2005, 
>> >>> 3, 20), datetime.date(2005, 2, 20)]>>> 
>> >>> Entry.objects.filter(headline__contains='Lennon').dates('pub_date', 
>> >>> 'day')[datetime.date(2005, 3, 20)]
>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/f6351f85-5dbf-47f3-a475-122fb52e6fa2%40googlegroups.com<https://groups.google.com/d/msgid/django-users/f6351f85-5dbf-47f3-a475-122fb52e6fa2%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
>
> Helton Alves 
> Desenvolvedor web
> Graduado em Sistemas de Informação - FACIMP
> Cursando Metodologia do Ensino Superior - INESPO
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABcoSmBznZKLD9uWa3nkW0-Tw6QPT7GJ8tTyS6FFYLUx-6U1Qw%40mail.gmail.com<https://groups.google.com/d/msgid/django-users/CABcoSmBznZKLD9uWa3nkW0-Tw6QPT7GJ8tTyS6FFYLUx-6U1Qw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BOnBTqWSpMJkU14vc%3DYW9cs16fNtGYyZVW%2Bdq2GVVmfaFA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: OneToOne? Inheritance? Another solution for nested model relationships?

2014-05-30 Thread Leonardo Giordani
I see your point. In this case I'd recommend giving Researcher two foreign
keys, one towards a Student model and one towards a Staff one, then add
some logic to the model to easily check the actual specialization or to
convert it among them. Basically you get a Researcher that "owns" a Student
or a Staff role.

Does this fit better? Let me know

Regards,

Leo

Leonardo Giordani
Author of The Digital Cat <http://lgiordani.github.com>
My profile on About.me <http://about.me/leonardo.giordani> - My GitHub page
<https://github.com/lgiordani> - My Coderwall profile
<https://coderwall.com/lgiordani>


2014-05-28 14:37 GMT+02:00 Daniele Procida :

> On Wed, May 28, 2014, Leonardo Giordani 
> wrote:
>
> >I usually solve such issues with Inheritance. I feel comfortable with it
> >because it lets me (in your example) to manage both ResearchStudent and
> >ResearchStaff independently, while keeping the Researcher parent model
> >available to deal with "global" queries and data interaction.
>
> It it were a case where abstract inheritance would work, I would agree.
> Unfortunately, the Researcher model can't be abstract (because it has its
> own relations with Publications).
>
> If I use multi-table inheritance, that solves part of the problem. However
> I don't know how well it would work if I have a Researcher, who at some
> point needs to be a ResearchStudent and maybe later becomes ResearchStaff.
>
> Regards,
>
> Daniele
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/20140528123744.1377784185%40smtpauth.cf.ac.uk
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEhE%2BOkKVXb-QKP5KNB003Q%3DrTGxane5vHMAwJETokbq%3D1H87A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.