Sunday, March 31, 2013

Re: Data Structure - Orders and multiple items

Sorry for the half response...please ignore the previous message.

class order(models.Model): 
    order_id = models.IntegerField(unique=True) 
    customer_id = models.ForeignKey('Customer')
    item_id = models.ForeignKey('Item')
    qty = models.IntegerField()

This will you give the provision to store multiple items to be added against each customer and the quantity of the order against each customer.

-Siddharth



On Mon, Apr 1, 2013 at 9:37 AM, Eric Lovrien <eric.lovrien@gmail.com> wrote:
I am not sure of how or the best way to structure my data in models.py. I would like to have an order and allow multiple items / products to be added to an order. I know I can do a ManyToMany field but not sure how I would connect a qty to that. I am sure there is some simple way of doing this, or a better way to model the data. I know in many ERP systems they have an orders table and then an orders details table. Below is just a quick mock-up of how i was thinking on to do it until I started thinking about the many items and qty to an single order issue came up. Can any one give me some tips on how to accomplish this? 



class Item(models.Model): 
    name = models.CharField(max_length200) 
    description = models.TextField(blank=True) 

    def __unicode__(self): 
         return self.name 

class Customer 
    first_name = models.CharField(max_length=100) 
    last_name = models.CharField(max_length=100) 
    address = models.CharField(max_length=200) 

    def __unicode__(self): 
        return self.name 

class order(models.Model): 
    order = models.IntegerField(unique=True) 
    customer = models.ForeignKey('Customer') 

--
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+unsubscribe@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?hl=en.
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: Data Structure - Orders and multiple items

Hi

As per my view you can modify your models as follows:-

class order(models.Model): 
    order_id = models.IntegerField(unique=True) 
    customer_id = models.ForeignKey('Customer')
    item_id = models.ForeignKey('Item')




On Mon, Apr 1, 2013 at 10:30 AM, Lachlan Musicman <datakid@gmail.com> wrote:
On 1 April 2013 15:07, Eric Lovrien <eric.lovrien@gmail.com> wrote:
> I am not sure of how or the best way to structure my data in models.py. I
> would like to have an order and allow multiple items / products to be added
> to an order. I know I can do a ManyToMany field but not sure how I would
> connect a qty to that. I am sure there is some simple way of doing this, or
> a better way to model the data. I know in many ERP systems they have an
> orders table and then an orders details table. Below is just a quick mock-up
> of how i was thinking on to do it until I started thinking about the many
> items and qty to an single order issue came up. Can any one give me some
> tips on how to accomplish this?


Use an intermediary model as described in the docs:

https://docs.djangoproject.com/en/1.5/topics/db/models/#extra-fields-on-many-to-many-relationships

This will be your best bet I think.

L.



>
>
>
> class Item(models.Model):
>     name = models.CharField(max_length200)
>     description = models.TextField(blank=True)
>
>     def __unicode__(self):
>          return self.name
>
> class Customer
>     first_name = models.CharField(max_length=100)
>     last_name = models.CharField(max_length=100)
>     address = models.CharField(max_length=200)
>
>     def __unicode__(self):
>         return self.name
>
> class order(models.Model):
>     order = models.IntegerField(unique=True)
>     customer = models.ForeignKey('Customer')
>
> --
> 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+unsubscribe@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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
The new creativity is pointing, not making. Likewise, in the future,
the best writers will be the best information managers.

http://www.theawl.com/2013/02/an-interview-with-avant-garde-poet-kenneth-goldsmith

--
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+unsubscribe@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?hl=en.
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: Data Structure - Orders and multiple items

On 1 April 2013 15:07, Eric Lovrien <eric.lovrien@gmail.com> wrote:
> I am not sure of how or the best way to structure my data in models.py. I
> would like to have an order and allow multiple items / products to be added
> to an order. I know I can do a ManyToMany field but not sure how I would
> connect a qty to that. I am sure there is some simple way of doing this, or
> a better way to model the data. I know in many ERP systems they have an
> orders table and then an orders details table. Below is just a quick mock-up
> of how i was thinking on to do it until I started thinking about the many
> items and qty to an single order issue came up. Can any one give me some
> tips on how to accomplish this?


Use an intermediary model as described in the docs:

https://docs.djangoproject.com/en/1.5/topics/db/models/#extra-fields-on-many-to-many-relationships

This will be your best bet I think.

L.



>
>
>
> class Item(models.Model):
> name = models.CharField(max_length200)
> description = models.TextField(blank=True)
>
> def __unicode__(self):
> return self.name
>
> class Customer
> first_name = models.CharField(max_length=100)
> last_name = models.CharField(max_length=100)
> address = models.CharField(max_length=200)
>
> def __unicode__(self):
> return self.name
>
> class order(models.Model):
> order = models.IntegerField(unique=True)
> customer = models.ForeignKey('Customer')
>
> --
> 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+unsubscribe@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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
The new creativity is pointing, not making. Likewise, in the future,
the best writers will be the best information managers.

http://www.theawl.com/2013/02/an-interview-with-avant-garde-poet-kenneth-goldsmith

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Re: Hey! I'm recieving an index error when trying to import models, and I can't figure out why.

When importing Python modules, you don't need to include the '.py' file extension. So,
from models.py import UUID
...needs to be:
from models import UUID

Hope this helps,
Jonathan


On Sun, Mar 31, 2013 at 10:27 PM, C Alaric Moore <alaricmeister@gmail.com> wrote:
Hello,

I am incredibly new to Django, as-of-today new, so forgive me if I've missed something really obvious.

I've been going through the tutorial and did so mostly-successfully and decided to redo it with my own code.

Everything was going fine until I decided that it would be a good idea to type from models.py import UUID, Students into the shell. With this I received the following error:

/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/db/models/base.pyc in __new__(cls, name, bases, attrs)
     90             # For 'django.contrib.sites.models', this would be 'sites'.

     91             model_module = sys.modules[new_class.__module__]
---> 92             kwargs = {"app_label": model_module.__name__.split('.')[-2]}
     93         else:
     94             kwargs = {}

IndexError: list index out of range

I went onto stackoverflow and found some people had similar issues a year ago, and suggested that a person delete the pyc files, which I did. It was also suggested that you make DEBUGGING = False, or True or whatever is opposite. I did this, too, only to find the same error.

I did some other things too, all to no avail... all the same error. I even checked to make sure I was saving edited files, TWICE. Still, same error.

With this, I ask for your help o' wise ones.

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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Jonathan D. Baker
Developer
http://jonathandbaker.com

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Hey! I'm recieving an index error when trying to import models, and I can't figure out why.

Hello,

I am incredibly new to Django, as-of-today new, so forgive me if I've missed something really obvious.

I've been going through the tutorial and did so mostly-successfully and decided to redo it with my own code.

Everything was going fine until I decided that it would be a good idea to type from models.py import UUID, Students into the shell. With this I received the following error:

/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/db/models/base.pyc in __new__(cls, name, bases, attrs)
     90             # For 'django.contrib.sites.models', this would be 'sites'.

     91             model_module = sys.modules[new_class.__module__]
---> 92             kwargs = {"app_label": model_module.__name__.split('.')[-2]}
     93         else:
     94             kwargs = {}

IndexError: list index out of range

I went onto stackoverflow and found some people had similar issues a year ago, and suggested that a person delete the pyc files, which I did. It was also suggested that you make DEBUGGING = False, or True or whatever is opposite. I did this, too, only to find the same error.

I did some other things too, all to no avail... all the same error. I even checked to make sure I was saving edited files, TWICE. Still, same error.

With this, I ask for your help o' wise ones.

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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Data Structure - Orders and multiple items

I am not sure of how or the best way to structure my data in models.py. I would like to have an order and allow multiple items / products to be added to an order. I know I can do a ManyToMany field but not sure how I would connect a qty to that. I am sure there is some simple way of doing this, or a better way to model the data. I know in many ERP systems they have an orders table and then an orders details table. Below is just a quick mock-up of how i was thinking on to do it until I started thinking about the many items and qty to an single order issue came up. Can any one give me some tips on how to accomplish this? 



class Item(models.Model): 
    name = models.CharField(max_length200) 
    description = models.TextField(blank=True) 

    def __unicode__(self): 
         return self.name 

class Customer 
    first_name = models.CharField(max_length=100) 
    last_name = models.CharField(max_length=100) 
    address = models.CharField(max_length=200) 

    def __unicode__(self): 
        return self.name 

class order(models.Model): 
    order = models.IntegerField(unique=True) 
    customer = models.ForeignKey('Customer') 

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: how do I specify optional params in url?

Ok, I understand and will try and provide more detail in the future.

Thanks again

On Sunday, March 31, 2013 5:28:54 PM UTC-4, Alexis Roda wrote:
Al 31/03/13 22:43, En/na frocco ha escrit:
> Thank you for taking the time to help me.

You're welcome.

One last thing. I'm not a native english speaker, so if I sound rude
it's not my intention. That said ...

When you ask for help in the list try to include more information: the
error message, explain what you're doing, what input do you provide,
what result do you expect and what result do you get, provide some
sample code etc.

Try to be clear and concise .. but not as concise as "this does not work" ;)

Also, when replying to a message keep some of the relevant context. That
will help the reader in knowing what has been done so far.


In short: help us to help you.



Regards

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: Using Django docs to find widget readonly specification

Al 31/03/13 23:42, En/na AJP ha escrit:
> I'm new to learning Django. I want to find the documentation regarding
> the readonly attribute you can set for admin widgets.

Do you mean?

https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#django.contrib.admin.ModelAdmin.readonly_fields

It's linked in the front page (https://docs.djangoproject.com/en/1.5/),
in the "The admin" section, "Admin site".

Also, googling for "django admin readonly field" returns the page in the
first place.


Regards

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Using Django docs to find widget readonly specification

I'm new to learning Django.  I want to find the documentation regarding the readonly attribute you can set for admin widgets.  For example, from an admin.py:

class SourceForm(forms.ModelForm):
  data = forms.CharField(widget=TextInput(attrs={'readonly': True, 'class': 'averageField'}))

  class Meta:
    model = Source


class SourceAdmin(admin.ModelAdmin):
  form = SourceForm

admin.site.register(Source, SourceAdmin)

I've search for readonly on https://docs.djangoproject.com/search/?q=readonly&release=7 but did not found anything.  Also searching manually in https://docs.djangoproject.com/en/dev/ref/forms/widgets/ didn't bring anything up.  Can someone tell me where I'm going wrong please.

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: how do I specify optional params in url?

Al 31/03/13 22:43, En/na frocco ha escrit:
> Thank you for taking the time to help me.

You're welcome.

One last thing. I'm not a native english speaker, so if I sound rude
it's not my intention. That said ...

When you ask for help in the list try to include more information: the
error message, explain what you're doing, what input do you provide,
what result do you expect and what result do you get, provide some
sample code etc.

Try to be clear and concise .. but not as concise as "this does not work" ;)

Also, when replying to a message keep some of the relevant context. That
will help the reader in knowing what has been done so far.


In short: help us to help you.



Regards

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

(1242, 'Subquery returns more than 1 row')

I have the following error in my project

(1242, 'Subquery returns more than 1 row')

my views are as given below

def result_cube(request):
Id = Cube.objects.aggregate(Max('Report_id'))
ID = Id['Report_id__max']
cubee = Cube.objects.filter(Report_id = ID)
Id = Report.objects.aggregate(Max('id'))
ID = Id['id__max']
Head = Report.objects.filter(id = ID)
organisation = Organisation.objects.all().filter(id = 1)
department = Department.objects.all().filter(id = 1)

Id = Report.objects.aggregate(Max('job'))
ID = Id['job__max']
job = Report.objects.filter(job = ID)

client =
Job.objects.all().filter(client=job).values('client__client__first_name',
'client__client__middle_name', 'client__client__last_name',
'client__client__address', 'client__client__city', 'date',
'letter_no', 'letter_date')

temp = {'client':client, 'cubee':cubee, 'Head':Head,
'organisation':organisation,'department':department,}
return render_to_response('report/cube.html',
dict(temp.items() + tmp.items()),
context_instance=RequestContext(request))


Error during template rendering

In template /home/satinder/Automation/templates/report/header.html,
error at line 12

2 {% load i18n %}
3 <html>
4 {% block content %}
5 <body>
6 {% for Heads in Head %}
7 <table width="100%"><tr>
8 <td align="left"><a>No.GNDEC/TCC/R/{{Heads.job_id}}</td><td
align="right"><a>Dated{{Heads.dispatch_report_date}}</a></td>
9 </tr></table>
10 <!-- <p><b>Job no:</b><a style="padding-left:30px;
position:absolute">{{Heads.job_no}}</a></p>
11 --> <p>To,</p>
12 {% for add in client %}
13 <p> {{ add.client__client__first_name}} {{
add.client__client__middle_name}}
{{add.client__client__last_name}}</p>
14 <p> {{add.client__client__address}}</p>
15 <p>{{ add.client__client__city}}</p>
16 {% endfor %}
17

Can anybody help me to solve this error.


--
Satinderpal Singh
http://devplace.in/~satinder/wordpress/
http://satindergoraya.blogspot.in/
http://satindergoraya91.blogspot.in/

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Re: I get import errors when I run django-admin.py startproject in Windows

Thanks for your help Karen.

I enter 
python C:\python33\scripts\django-admin.py startproject mysite

The response I get is
Traceback (most recent call last):
  File "C:\Python33\lib\site-packages\django\core\management\templates.py",
line  12, in <module>
    from urllib.request import urlretrieve
  File "C:\Python33\lib\urllib\request.py", line 88, in <module>
    import http.client
  File "C:\Python33\Lib\site-packages\django\http\__init__.py", line 1, in <module>
    from django.http.cookie import SimpleCookie, parse_cookie
  File "C:\Python33\lib\site-packages\django\http\__init__.py", line 1, in <module>
    from django.http.cookie import SimpleCookie, parse_cookie
  File "C:\Python33\lib\site-packages\django\http\cookie.py", line 5, in <module>
    from django.utils.six.moves import http_cookies
  File "C:\Python33\lib\site-packages\django\utils\six.py", line 84, in __get__
    result = self._resolve()
  File "C:\Python33\lib\site-packages\django\utils\six.py", line 103, in _resolve
    return _import_module(self.mod)
  File "C:\Python33\lib\site-packages\django\utils\six.py", line 74, in _import_module
    __import__(name)
ImportError: No module named 'http.cookies'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\python33\scripts\django-admin.py", line 5, in <module>
    management.execute_from_command_line()
  File "C:\Python33\lib\site-packages\django\core\management\__init__.py", line
453, in execute_from_command_line
    utility.execute()
  File "C:\Python33\lib\site-packages\django\core\management\__init__.py", line
392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python33\lib\site-packages\django\core\management\__init__.py", line
272, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "C:\Python33\lib\site-packages\django\core\management\__init__.py", line
77, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "C:\Python33\lib\site-packages\django\utils\importlib.py", line 35, in im
port_module
    __import__(name)
  File "C:\Python33\lib\site-packages\django\core\management\commands\startproje
ct.py", line 2, in <module>
    from django.core.management.templates import TemplateCommand
  File "C:\Python33\lib\site-packages\django\core\management\templates.py", line
 14, in <module>
    from urllib import urlretrieve
ImportError: cannot import name urlretrieve


My path includes my Python directory and Scripts sub-directory. My Python path includes Python\DLLs, Python\Scripts and Python\Lib\site-packages\django. I hope that this gives you the information you need to help me out. If not, please tell me what else I can provide. Thanks again for your help.


On Sunday, March 31, 2013 6:33:39 AM UTC-7, Karen Tracey wrote:
What errors, exactly? Without some specifics of what's going wrong it's hard to offer help. Copy/paste of exactly what you are entering and getting in response would 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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: how do I specify optional params in url?

Thank you for taking the time to help me.

On Sunday, March 31, 2013 1:00:24 PM UTC-4, frocco wrote:
Hello,

Here is my current url.

   url(r'^narrow_category/(\d+)/(\w*)/(\d*)/(\d*)/(\d*)/$', 'catalog.views.narrow_category', name="narrow_category"),

d+ is required
w* can be optional
last three d* can be optional

This setting is not working.

What am I doing wrong?

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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: how do I specify optional params in url?

Al 31/03/13 21:55, En/na frocco ha escrit:
> I am kinda lost with url encoding being a newbie in django.
>
> I do not see my error.
>
> Can you give me an example?

Here it is:

views.py:

def my_view(request, foo, bar="spam"):
pass

urls.py

# choose descriptive names for the views
...
url(r"^narrow/(\d+)/$", views.my_view, name="narrow1"),
url(r"^narrow/(\d+)/(\w+)/$", views.my_view, name="narrow2"),
...

in python code (views etc.):

reverse("narrow1", args=(23, )) -> ".../narrow/23/"
reverse("narrow2", args=(23, "foo")) -> ".../narrow/23/foo"

in templates:

{% url "narrow1" 23 %} -> ".../narrow/23/"
{% url "narrow2" 23 "foo" %} -> ".../narrow/23/foo/"

Important: if you're using django < 1.5 you should remove the quotes
around the view name in the url tag.




HTH

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Re: how do I specify optional params in url?

I am kinda lost with url encoding being a newbie in django.
I do not see my error.

 Can you give me an example?

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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: how do I specify optional params in url?



El diumenge 31 de març de 2013 21:01:55 UTC+2, frocco va escriure:
 url(r'^narrow_category/(\d+)/$', 'catalog.views.narrow_category', name="narrow_category"),
        url(r'^narrow_category/(\d+)/(\w+)/$', 'catalog.views.narrow_category', name="narrow_category"),
        url(r'^narrow_category/(\d+)/(\w+)/(\d+)/$', 'catalog.views.narrow_category', name="narrow_category"),
        url(r'^narrow_category/(\d+)/(\w+)/(\d+)/(\d+)/$', 'catalog.views.narrow_category', name="narrow_category"),
        url(r'^narrow_category/(\d+)/(\w+)/(\d+)/(\d+)/(\d+)/$', 'catalog.views.narrow_category', name="narrow_category"),

def narrow_category(request, pk, search='', size1='', size2='', size3=''):
 

Page not found (404)

Request Method:GET
Request URL:http://127.0.0.1:8000/narrow_category/8/2657018///

I missed this in my first read: you should give each rule a different name.


Regards

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: how do I specify optional params in url?

Al 31/03/13 21:01, En/na frocco ha escrit:
> url(r'^narrow_category/(\d+)/$', 'catalog.views.narrow_category',
> name="narrow_category"),
> url(r'^narrow_category/(\d+)/(\w+)/$',
> 'catalog.views.narrow_category', name="narrow_category"),
> url(r'^narrow_category/(\d+)/(\w+)/(\d+)/$',
> 'catalog.views.narrow_category', name="narrow_category"),
> url(r'^narrow_category/(\d+)/(\w+)/(\d+)/(\d+)/$',
> 'catalog.views.narrow_category', name="narrow_category"),
> url(r'^narrow_category/(\d+)/(\w+)/(\d+)/(\d+)/(\d+)/$',
> 'catalog.views.narrow_category', name="narrow_category"),
>
> def narrow_category(request, pk, search='', size1='', size2='', size3=''):
>
>
> Page not found (404)
>
> Request Method: GET
> Request URL: http://127.0.0.1:8000/narrow_category/8/2657018///


Take a look carefully at the URL that's causing the error:

http://127.0.0.1:8000/narrow_category/8/2657018///

does it matches any of your rules?



HTH

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Re: how do I specify optional params in url?

 url(r'^narrow_category/(\d+)/$', 'catalog.views.narrow_category', name="narrow_category"),
        url(r'^narrow_category/(\d+)/(\w+)/$', 'catalog.views.narrow_category', name="narrow_category"),
        url(r'^narrow_category/(\d+)/(\w+)/(\d+)/$', 'catalog.views.narrow_category', name="narrow_category"),
        url(r'^narrow_category/(\d+)/(\w+)/(\d+)/(\d+)/$', 'catalog.views.narrow_category', name="narrow_category"),
        url(r'^narrow_category/(\d+)/(\w+)/(\d+)/(\d+)/(\d+)/$', 'catalog.views.narrow_category', name="narrow_category"),

def narrow_category(request, pk, search='', size1='', size2='', size3=''):
 

Page not found (404)

Request Method:GET
Request URL:http://127.0.0.1:8000/narrow_category/8/2657018///

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: how do I specify optional params in url?

Al 31/03/13 19:00, En/na frocco ha escrit:
> Hello,
>
> Here is my current url.
>
> url(r'^narrow_category/(\d+)/(\w*)/(\d*)/(\d*)/(\d*)/$',
> 'catalog.views.narrow_category', name="narrow_category"),
>
> d+ is required
> w* can be optional
> last three d* can be optional
>
> This setting is not working.

You should be a bit more explicit about what "is not working" means.

I presume that you expect that an URL like "narrow_category/23" should
be matched against your url definition. No, it won't, since the slashes
are not optional. All those will match against your regular expression:

narrow_category/23/////
narrow_category/23/foo////
narrow_category/23/45////
narrow_category/23///23//

I think that the cleanest solution is defining a set of urls and,
somehow, provide default values for the missing parts:

def my_view(request, foo, bar="spam", baz=1234):
pass

url(r"^narrow/(\d+)/$", views.my_view, ...)
url(r"^narrow/(\d+)/(\w+)/$", views.my_view, ...)
url(r"^narrow/(\d+)/(\w+)/(\d+)/$", views.my_view, ...)

Note that the parts are no longer optional (+ instead of *).

It works like this:

/narrow/23/
matches the 1st rule
django calls: my_view(request, "23")
the view gets the arguments: foo="23", bar="spam", baz=1234

/narrow/23/baz/
2nd rule
my_view(request, "23", "baz")
foo="23", bar="baz", baz=1234

/narrow/23/baz/45/
3rd rule
my_view(request, "23", "baz", "45")
foo="23", bar="baz", baz="45"

/narrow/23/45/
2nd rule
my_view(request, "23", "45")
foo="23", bar="45", baz=1234


HTH

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

how do I specify optional params in url?

Hello,

Here is my current url.

   url(r'^narrow_category/(\d+)/(\w*)/(\d*)/(\d*)/(\d*)/$', 'catalog.views.narrow_category', name="narrow_category"),

d+ is required
w* can be optional
last three d* can be optional

This setting is not working.

What am I doing wrong?

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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: How do I get these field values in my template?

Thank you

On Sunday, March 31, 2013 10:17:35 AM UTC-4, Alexis Roda wrote:
Al 31/03/13 15:18, En/na frocco ha escrit:
> cat = Product.objects.values_list('category__image_path','category__id')
>
> outputs;
> (u'category/goodyear logo.jpg', 13)
>
> I tried for c in cat:
> c.image_path
> c.id

As its name may suggest values_lists() returns (kind) a list of lists,
so you must index by position, not by field name:

for c in cat:
     print c[0], c[1]

{% for c in cat %}
    <p>{{ c.0 }} {{c.1}}</p>
{% endfor %}

If you want to index by field name you should use values(), which
returns a list of dictionaries mapping "field name" to "value".



HTH

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: Filtering M2M in Admin Interface

Answering myself, but for future searchers.
This is related to this bug report
https://code.djangoproject.com/ticket/14891 as well as this
discussion http://goo.gl/ac5lg
So for now I'll figure out a work around with QuerySets and indexes,
instead of using keys.

Cheers,
Tim

On Sat, Mar 30, 2013 at 1:40 PM, Tim Cook <tim@mlhim.org> wrote:
> Hi All,
>
> I have a scenario setup very much like the Polls example in the tutorial.
>
> class Terminology(models.Model):
> name = models.CharField(max_length=110)
> abbreviation = models.CharField(max_length=20)
> version = models.CharField(max_length=30)
>
> def __unicode__(self):
> return self.name + " : " + self.version
>
> class Codes(models.Model):
> terminology = models.ForeignKey(Terminology)
> code_string = models.CharField(max_length=110)
> code = models.CharField(max_length=20)
> url = models.URLField(verbose_name="Reference", help_text="An
> optional reference to the description for the code.", blank=True)
>
> def __unicode__(self):
> return self.code + " : " + self.code_string
>
>
> Now to extend this a bit.
>
> class DvCodedString(DvString):
> terminology = models.ForeignKey(Terminology, null=True, blank=True)
> codes = models.ManyToManyField(Codes, null=True, blank=True)
> ...
>
>
> My admin models:
> class CodesInline(admin.TabularInline):
> model = Codes
> extra = 5
>
> class TerminologyAdmin(admin.ModelAdmin):
> fieldsets = (
> (None, {'classes':('wide',),
> 'fields':('abbreviation','version','name',)}),
> )
> inlines = [CodesInline]
> admin.site.register(Terminology, TerminologyAdmin)
>
>
> class DvCodedStringAdmin(admin.ModelAdmin):
> fieldsets = (
> (None, {'classes':('wide',),
> 'fields':('published','prj_name','data_name',)}),
> ("Basic", {'classes':('collapse',),
> 'fields':('terminology','codes',),
> 'description':'When all codes come from one
> terminology (and one version of it).'}),
>
> ...
>
> Currently all codes will be shown in the select box.
> But of course what I really want is the Terminology Choice to filter
> the available codes displayed.
>
> So, my question is:
> Where can I find the relevant documentation on doing this in the admin
> interface?
> Or can it be done in the admin interface?
>
> Thanks,
> Tim
>
>
>
>
>
> --
> ============================================
> Timothy Cook, MSc +55 21 94711995
> MLHIM http://www.mlhim.org
> Like Us on FB: https://www.facebook.com/mlhim2
> Circle us on G+: http://goo.gl/44EV5
> Google Scholar: http://goo.gl/MMZ1o
> LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook



--
============================================
Timothy Cook, MSc +55 21 94711995
MLHIM http://www.mlhim.org
Like Us on FB: https://www.facebook.com/mlhim2
Circle us on G+: http://goo.gl/44EV5
Google Scholar: http://goo.gl/MMZ1o
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Re: How do I get these field values in my template?

Al 31/03/13 15:18, En/na frocco ha escrit:
> cat = Product.objects.values_list('category__image_path','category__id')
>
> outputs;
> (u'category/goodyear logo.jpg', 13)
>
> I tried for c in cat:
> c.image_path
> c.id

As its name may suggest values_lists() returns (kind) a list of lists,
so you must index by position, not by field name:

for c in cat:
print c[0], c[1]

{% for c in cat %}
<p>{{ c.0 }} {{c.1}}</p>
{% endfor %}

If you want to index by field name you should use values(), which
returns a list of dictionaries mapping "field name" to "value".



HTH

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Re: I get import errors when I run django-admin.py startproject in Windows

What errors, exactly? Without some specifics of what's going wrong it's hard to offer help. Copy/paste of exactly what you are entering and getting in response would 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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

How do I get these field values in my template?

cat = Product.objects.values_list('category__image_path','category__id')

outputs;
(u'category/goodyear logo.jpg', 13) 

I tried for c in cat:
c.image_path
c.id

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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

I get import errors when I run django-admin.py startproject in Windows

I get import errors when I run django-admin.py startproject for the first time in Windows 7. I installed Django 1.5.1 and I am trying to use that with Python 3.3. Any ideas about how to get past this hurdle? I am new to Django.

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

my project is not working in virtualenv in ubuntu?

hi,
   please tell me,what is issue with me, I am using virtualenv in ubuntu, i am fine in window,but here it's not showing admin pages,
   I have installed apache2 and wsgi, i want to run my project through my own apache2.but its not showing
my pages-
/var/www/mydomain.com/index.py 

import os
import sys
import site

# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('~/.virtualenvs/DJ/local/lib/python2.7/site-packages')

# Add the app's directory to the PYTHONPATH
sys.path.append('/home/avnProject/avnProject')
sys.path.append('/home/avnProject/avnProject/avnproject')

os.environ['DJANGO_SETTINGS_MODULE'] = 'avnproject.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

AND
second file is-- path
/etc/apache2/sites-available/mydomain.com

<VirtualHost *:80>
    ServerAdmin avnesh@techhue.com
    ServerName localhost
    ServerAlias mydomain.com
    WSGIScriptAlias / var/www/mydomain.com/index.wsgi

    Alias /static/ /var/www/mydomain.com/static/
    <Location "/static/">
        Options -Indexes
    </Location >
</VirtualHost >

Myproject directory is ---- /home/avin/avnProject/

please help me....
i m trying localhost/mydomain.com then fine when I put localhost/mydomain.com/index.wsgi,then it's downloading it......
and i m unable to open admin page here


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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: Question about documentauion under Managers>Adding extra Manager methods


Unless I'm mistaken, it's PostgreSQL. The telling feature is the GROUP BY clause - PostgreSQL allows you to group by column index.


Since this is an eccentricity of PostgreSQL, it would be a good idea for us to modify that example in the docs, and use a more conventional GROUP BY statement that would be familiar to all SQL dialects. I've opened ticket #20168 to track this issue.

Yours,
Russ Magee %-)

On Sun, Mar 31, 2013 at 5:49 AM, James Durham <jamesldurham@gmail.com> wrote:
In this instance, what I'm asking is about the documentation.
In other words does anyone recognize the dialect.
It would just help in understanding docs.
Though, thanks for indicating that it is backend dependent.

On Friday, March 29, 2013 8:40:09 PM UTC-5, Russell Keith-Magee wrote:


On Sat, Mar 30, 2013 at 6:20 AM, James Durham <jamesl...@gmail.com> wrote:
In the example:
class PollManager(models.Manager):      def with_counts(self):          from django.db import connection          cursor = connection.cursor()          cursor.execute("""              SELECT p.id, p.question, p.poll_date, COUNT(*)              FROM polls_opinionpoll p, polls_response r              WHERE p.id = r.poll_id              GROUP BY 1, 2, 3              ORDER BY 3 DESC""")          result_list = []          for row in cursor.fetchall():              p = self.model(id=row[0], question=row[1], poll_date=row[2])              p.num_responses = row[3]              result_list.append(p)          return result_list    class OpinionPoll(models.Model):      question = models.CharField(max_length=200)      poll_date = models.DateField()      objects = PollManager()    class Response(models.Model):      poll = models.ForeignKey(OpinionPoll)      person_name = models.CharField(max_length=50)      response = models.TextField()

What is the sql dialect that is used.
In this case you're opening a cursor, so you use whatever dialect your database uses. If you're using PostgreSQL, use PostgreSQL syntax; if you're using MySQL, use MySQL syntax. 

Django's ORM hides syntax differences from you; but once you start dealing with database cursors or raw() queries, you're coding right to the metal, so your deployment environment matters.

Yours,
Russ Magee %-)

--
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+unsubscribe@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?hl=en.
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Saturday, March 30, 2013

Re: Question about documentauion under Managers>Adding extra Manager methods

In this instance, what I'm asking is about the documentation.
In other words does anyone recognize the dialect.
It would just help in understanding docs.
Though, thanks for indicating that it is backend dependent.

On Friday, March 29, 2013 8:40:09 PM UTC-5, Russell Keith-Magee wrote:


On Sat, Mar 30, 2013 at 6:20 AM, James Durham <jamesl...@gmail.com> wrote:
In the example:
class PollManager(models.Manager):      def with_counts(self):          from django.db import connection          cursor = connection.cursor()          cursor.execute("""              SELECT p.id, p.question, p.poll_date, COUNT(*)              FROM polls_opinionpoll p, polls_response r              WHERE p.id = r.poll_id              GROUP BY 1, 2, 3              ORDER BY 3 DESC""")          result_list = []          for row in cursor.fetchall():              p = self.model(id=row[0], question=row[1], poll_date=row[2])              p.num_responses = row[3]              result_list.append(p)          return result_list    class OpinionPoll(models.Model):      question = models.CharField(max_length=200)      poll_date = models.DateField()      objects = PollManager()    class Response(models.Model):      poll = models.ForeignKey(OpinionPoll)      person_name = models.CharField(max_length=50)      response = models.TextField()

What is the sql dialect that is used.
In this case you're opening a cursor, so you use whatever dialect your database uses. If you're using PostgreSQL, use PostgreSQL syntax; if you're using MySQL, use MySQL syntax. 

Django's ORM hides syntax differences from you; but once you start dealing with database cursors or raw() queries, you're coding right to the metal, so your deployment environment matters.

Yours,
Russ Magee %-)

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: Displaying And Selecting Tags in Admin Site

Hi again

Have tried out this app and it is exactly what I was looking for!
I strongly recommend it for anyone who wants an easy way to manage attaching and removing tags in the admin site
Thanks again for your help : )

Jon

On Thursday, March 28, 2013 1:33:11 PM UTC, Jonathan Harris wrote:
Hi All

New to Django and coding in general, so sorry if this has been covered - I did search the group postings, have read the documentation, trawled the net etc, but couldn't find anything directly relevant

I have been following various tutorials (django homepage, youtube etc) for how to start creating a blog site

What I would like to do seems really simple, but I cannot find a solution

Django 1.5 on Ubuntu Server 12.04LTS

It uses Taggable Manager, so in models.py we see

#models.py

from taggit.managers import TaggableManager

class Post(models.Model):
    title = models.CharField(max_length=100)
    ....
    tags = TaggableManager()

#admin.py

from blog.models import Post

class PostAdmin(admin.ModelAdmin):
    fieldsets = [
        ('Title',      {'fields': ['title']}),
        ......
        ('Tags',     {'fields': ['tags'], 'classes': ['collapse']}),
    ]

admin.site.register(Post, PostAdmin)

____

This works fine

What I would like to do is change the way that tags can be viewed and selected in the admin site

Currently, it is as a comma separated list

I would like to pre-create the tags, then see them in a drop down, or table, or similar, so that one or more may be selected
The view I am looking to achieve would be as if 'filter_horizontal = ['tags']' had been applied

However, I cannot find a way to do it

I have tried to give the tags a separate class, with a ManyToManyField link into Post, but any tags that are created are not displayed - and this is probably really not the right approach

So is it possible to change the way that tags from TaggableManager is displayed? Can it be as a selection box, or check boxes or anything else? Or are we stuck with the list approach?

Any advice would be gratefully received

Many Thanks

Jon

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: Doubt regarding JSON/SQL in Django

Al 30/03/13 19:25, En/na Parin Porecha ha escrit:
> Yes, I meant the former ( managing presentation on the client ).
>
> Also, considering that a user might have as many as 100 - 200 tasks in
> one JSON file ( their description, dates, tags and all ),
> is it better performance wise ?

The responsiveness of the application will be better. By the way, you're
not required to load all the tasks at a time, you can paginate the query
result and request chunks of data from the server as the user scrolls
down the list.



Regards

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Re: FileField delete and update handling

Please have a look at following code.

pre_save and post_delete signal handlers are used here to
automatically delete unused files.

Signal handlers are generic in nature as the use isinstance(field,
models.FileField) to identify file fields.

Source - https://github.com/un1t/django-cleanup/blob/master/django_cleanup/models.py.

import os
from django.db import models
from django.db.models.signals import pre_save, post_delete
from django.db.models.loading import cache


def find_models_with_filefield():
result = []
for app in cache.get_apps():
model_list = cache.get_models(app)
for model in model_list:
for field in model._meta.fields:
if isinstance(field, models.FileField):
result.append(model)
break
return result

def remove_old_files(sender, instance, **kwargs):
if not instance.id:
return

try:
old_instance = instance.__class__.objects.get(id=instance.id)
except instance.DoesNotExist:
return

for field in instance._meta.fields:
if not isinstance(field, models.FileField):
continue
old_file = getattr(old_instance, field.name)
new_file = getattr(instance, field.name)
if old_file and old_file != new_file and os.path.exists(old_file.path):
try:
os.remove(old_file.path)
except OSError:
pass

def remove_files(sender, instance, **kwargs):
for field in instance._meta.fields:
if not isinstance(field, models.FileField):
continue
file = getattr(instance, field.name)
if file and os.path.exists(file.path):
try:
os.remove(file.path)
except OSError:
pass


for model in find_models_with_filefield():
pre_save.connect(remove_old_files, sender=model)
post_delete.connect(remove_files, sender=model)

On Sat, Mar 30, 2013 at 9:57 PM, <temp4746@gmail.com> wrote:
> Hi,
>
> As it seems Django doesn't handle the update and delete of files from a
> FileField by itself leaving you them pretty hard to use by default.
>
> I tried search around but couldn't find a proper answer as to the correct
> way of handling this.
>
> I'm looking for the case where when the file is updated to a new name or
> deleted, it will be deleted properly from the file system, preferably not
> leaving empty directories too.
>
> Not having this done at the model level means all the generic views and
> admin pages are useless and require customization to delete and update the
> file name in them.
>
> The other option is a script that is going to iterate the entire directory
> and look for files not listed in the db, which is a really expensive and
> slow operation.
>
> --
> 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+unsubscribe@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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--

Sincerely,
Pankaj Singh
http://about.me/psjinx

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Re: Doubt regarding JSON/SQL in Django

If you don't use the ORM, Forms, and even the templating system you're losing quite a bit with Django. In my opinion, it's not worth using Django for those sorts of projects.

While not a Python project, I found NodeJS & node-restify a good candidate for these types of applications. That's not a conclusive alternative as I honestly didn't put a *lot* of time into looking at Python alternatives since this one merged so seamlessly into our technologies (Backbone.js, MongoDB, Web-Service)

Also, there's some Django Rest Modules which can help automate some Object->JSON (RESTful) functionality


On Sat, Mar 30, 2013 at 2:16 PM, Alexis Roda <alexis.roda.villalonga@gmail.com> wrote:
Al 30/03/13 16:41, En/na Parin Porecha ha escrit:

Thanks !

Okay, so i am dropping the idea of using JSON for storage.

So, if I use JSON only as a format to send data
to client ( All the parsing will be done client side ), is it better
than using {{ task.name }}, {{ task.start_date }} ? ( Sorry to ask
this again, but i haven't got it )

Sorry, but I still don't get the point on your question. Do you mean "is better to manage presentation on the client (json response + javascript) or in the server (django templates)"?



Regards


--
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+unsubscribe@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?hl=en.
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: Doubt regarding JSON/SQL in Django

Yes, I meant the former ( managing presentation on the client ).

Also, considering that a user might have as many as 100 - 200 tasks in
one JSON file ( their description, dates, tags and all ),
is it better performance wise ?

On Sat, Mar 30, 2013 at 11:46 PM, Alexis Roda
<alexis.roda.villalonga@gmail.com> wrote:
> Al 30/03/13 16:41, En/na Parin Porecha ha escrit:
>
>> Thanks !
>>
>> Okay, so i am dropping the idea of using JSON for storage.
>>
>> So, if I use JSON only as a format to send data
>> to client ( All the parsing will be done client side ), is it better
>> than using {{ task.name }}, {{ task.start_date }} ? ( Sorry to ask
>> this again, but i haven't got it )
>
>
> Sorry, but I still don't get the point on your question. Do you mean "is
> better to manage presentation on the client (json response + javascript) or
> in the server (django templates)"?
>
>
>
> Regards
>
>
> --
> 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+unsubscribe@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?hl=en.
> 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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Re: FileField delete and update handling

You could remember the old path by saving it as a variable in your
model's __init__ function.

Something like this:

self._old_file_path = self.file_path

Then in your save():

#only if there was a non-blank path to begin with, and it changed
if self._old_file_path and ( self._old_file_path != self.file_path):

os.remove(self._old_file_path

I don't know if this is the best possible solution, but it would
guarantee that this would happen automatically from the admin and your
ModelForms without any extra code.

--
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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.