Re: TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

2021-11-20 Thread Peter of the Norse
CommentForm inherits from both ModelForm and “forms”.  I don’t know what 
“forms” is, but PEP-8 says all classes should be capitalized.  If forms is a 
base class that has already defined Meta, then you need to have CommentForm’s 
extend it.  So change the line to class Meta(forms.Meta):

> On Oct 28, 2021, at 8:18 PM, Sabbir Hasan Munna  
> wrote:
> 
> 
> 
> 
> -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/f7d8a010-0f68-437c-b3df-ec99a4460aafn%40googlegroups.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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/E4AE72BA-48B0-4AD8-9D63-4AE9663F7C10%40gmail.com.


Re: Question regarding organizing models

2021-11-14 Thread Peter of the Norse
You can put a string with the name of a class that is yet to be defined in the 
ForeignKey.  
https://docs.djangoproject.com/en/3.2/ref/models/fields/#foreignkey 


In this case you would do

created_by_id = models.ForeignKey("User", on_delete=models.DO_NOTHING)

> On Sep 23, 2021, at 1:50 AM, Bhavin Shah  wrote:
> 
> Hello,
> 
> Somewhat new to Django. I am trying to figure out the best way to 
> define/organize models in Django app which have interdependent foreign keys. 
> Simplified example below.
> 
> 
> 
> 
> The issue I am struggling with is the following
> The above example produces an error as User class is defined after Company. 
> Reversing the order would cause the same issue with reference to Company 
> class in User class. What is the best way to handle this scenario ? I tried 
> to set the created_by_id value post the User class declaration, but then the 
> django migrations do not recognize/set the foreign key correctly.
> I also tried to split the models into multiple files as the app is expected 
> to have several models with such interdependent foreign keys. However in that 
> scenario, the import are causing an error due to circular references.
> Any suggestions/guidance on best way to handle such models would be very much 
> appreciated. Thank you.
> 
> Regards,
> 
> Bhavin Shah
> 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/A001F887-DF85-4B6D-AA85-FB298A2AC9CA%40gmail.com.


Re: Idea

2021-10-31 Thread Peter of the Norse
Most of the people that think switching to node.js only know PHP.  That’s why 
it looks like a good idea.

> On Sep 20, 2021, at 2:46 AM, David Nugent  wrote:
> 
> This is almost the same case that nodejs users have put forward since it was 
> invented - why learn 2 languages when 1 will do?  node backend and js front 
> end, one language.
> 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/380EFF57-ED6C-493B-AD3E-921FC1F1AB98%40gmail.com.


Re: Idea

2021-10-31 Thread Peter of the Norse
I’m worried that you are getting on the wrong track here.  All web development 
is necessarily client-server based.  One of the signs of a poorly designed VB 
application is the way that you can put DB code in a button action.  That isn't 
possible in a browser.  Instead all it can do is contact the server.  

There are several options for running Python in the browser instead of JS, but 
even if you use them the framework is different.  You can’t really use Django 
in a browser, and you can’t use the DOM on a server.  Every attempt to mix them 
has had way too many issues.

> On Sep 18, 2021, at 2:44 PM, Jet Ezra  wrote:
> 
> I know this may not be necessary at the moment because we are comfortable 
> depending on front-end frameworks, but I have my two ideas here:
> 1. what if django alone without any framework can be used to design 
> progressive web apps, with routers that do not reload the page, we currently 
> have one of the best routing but what if they support SPAs this time?
> 2. what if we could instead of Javascript in the templates, we write python, 
> case in example is forexample how we write C# in .NET withing our templates 
> not writing JavaScript. Currently DJango is requiring its developer to again 
> go ahead and learn JS too, what if we remove that??
>  

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/D8CCA74C-3EF9-466E-8B7C-B382590B1B48%40gmail.com.


Re: Django 3.1 Makemigrations fails with FilePathField but succeeds with CharField

2021-06-22 Thread Peter of the Norse
I think you might be better off using 
https://docs.djangoproject.com/en/3.2/topics/migrations/#squashing-migrations 
 
than having it recreate all of them.  

> On Mar 18, 2021, at 8:28 AM, Olivier  wrote:
> 
> Hello,
> 
> I've got a Django app which has over 200 migration steps.
> To shorten its test loading time, I'm trying to erase all current migrations 
> and restart from scratch.
> 
> I deteted and re-created my app Postgres database.
> I deleted all files (but __init__.py) in migrations directory.
> I typed "python manage.py makemigrations --verbosity 3".
> 
> 1. Latest makemigrations failed with:
>   File 
> "/home/perenip/venv-flexcore/lib/python3.7/site-packages/django/db/migrations/serializer.py",
>  line 339, in serializer_factory
> "topics/migrations/#migration-serializing" % (value, get_docs_version())
> ValueError: Cannot serialize: PosixPath('/var/www/vhosts/foo/vendorstatic')
> There are some values Django cannot serialize into migration files.
> For more, see 
> https://docs.djangoproject.com/en/3.1/topics/migrations/#migration-serializing
> 
> If I'm not mistaken, I couldn't read any reference to the Model/Field that 
> triggered the error.
> Should we expect an explicit mention of the faulty statement/line ?
> 
> 2. I edited a Model within models.py with:
> class Firmware(models.Model):
> #filepath = models.FilePathField(path=settings.VENDOR_STATIC_ROOT, 
> match=settings.FIRMWARE_REGEX, recursive=True)
> filepath = models.CharField(max_length=64)
> display_name = models.CharField(default='foobar', max_length=32, 
> help_text='Value as shown in HTTP User-Agent string')
> 
> def __str__(self):
> return self.relative_path()
> 
> def relative_path(self):
> return 
> str(pathlib.Path(self.filepath).relative_to(settings.VENDOR_STATIC_ROOT))
> 
> After changing from a PathFileField to a CharFiled as shown above, I could 
> successfully run makemigrations.
> 
> Doc [1] mentions Django can serialize "any Django field". Should it serialize 
> FilePathField ?
> [1] 
> https://docs.djangoproject.com/en/3.1/topics/migrations/#migration-serializing
> 
> 3. How to work around this with rewriting my app (and its tests) ?
> 
> 
> Best 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+unsubscr...@googlegroups.com 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/739e8a51-ed79-476c-9945-1076a0491b75n%40googlegroups.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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CE1E3974-F647-4DA3-BB6E-215B31BDC373%40gmail.com.


Re: Question about models. test

2021-05-02 Thread Peter of the Norse
This kind of script can be dangerous.  It’s possible for malicious websites to 
create a page that can use up too many resources or otherwise act strangely.  
URLValidator 

 used to do this kind of thing optionally, but that was removed because of all 
of the problems it caused.  If you do try visiting all of the websites, make 
sure you have a low timeout and don’t follow redirects.

> On Feb 25, 2021, at 3:50 PM, Ryan Nowakowski  wrote:
> 
> On Thu, Feb 25, 2021 at 01:06:00AM -0500, dupakoor kannan wrote:
>> I have the following model
>> 
>> class Publication(models.Model):
>>name = models.CharField(max_length=25, blank=True, null=False)
>>publication_url = models.TextField(blank=True)
> 
> Once you clean out all the bad data, you might want to migrate from
> TextField to URLField here.  That would help prevent data entry
> mistakes assuming some of the errors are invalid URLs.
> 
> One other suggestion, even though you didn't ask :)  I'd rename
> publication_url to just url since it's a part of the Publication model,
> the "publication" part is redundant.
> 
>> and observed there are some inactive URLs on the production server (due to
>> data entry mistakes). Is there any way I can write a test for the inactive
>> URLs from the database (local copy)?.
> 
> I assume "inactive" here means that the URLs are returning HTTP 404.
> For the test, you can run this in `python manage.py shell`:
> 
> import requests  # you'll need to pip install requests
> 
> for publication in Publication.objects.all():
>   response = requests.get(publication.publication_url)
>   try:
>   response.raise_for_status()
>   except requests.exceptions.HTTPError:
>   # do something here with your "inactive" URL
>   pass
> 
> 
> If you want to make this easier to run in the future, I suggest making a
> custom management command[1].  If you want this test to run anytime
> Publication.save() is called, add a validator[2] to publication_url.
> 
> [1] https://docs.djangoproject.com/en/3.1/howto/custom-management-commands/
> [2] https://docs.djangoproject.com/en/3.1/ref/validators/
> 
> -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/20210225225044.GE19963%40fattuba.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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1EE85283-F866-45F5-B355-0B75CCCB830E%40gmail.com.


Re: QuerySet performance on large datasets

2021-04-11 Thread Peter of the Norse
Follow up to my own message.  I found a way of testing this that I think 
everyone should look at:

$ ./manage.py shell
Python 3.8.5 (default, Jul 21 2020, 10:48:26)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import logging
>>> l = logging.getLogger('django.db.backends')
>>> l.setLevel(logging.DEBUG)
>>> l.addHandler(logging.StreamHandler())

This will allow you to see what SQL is actually being run.  That way you can do 
things like comparing which statement is faster when you do things side by side.

>>> from django.contrib.auth.models import User
>>> qs = User.objects.all()
>>> val = qs.earliest('date_joined') if qs.exists() else None
(0.000) SELECT (1) AS "a" FROM "auth_user" LIMIT 1; args=()
(0.026) SELECT "auth_user"."id", "auth_user"."password", 
"auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", 
"auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", 
"auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined" FROM 
"auth_user" ORDER BY "auth_user"."date_joined" ASC LIMIT 1; args=()
>>> qs = User.objects.all()  # Don’t use the cache
>>> val = qs.earliest('date_joined') if bool(qs) else None
(0.024) SELECT "auth_user"."id", "auth_user"."password", 
"auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", 
"auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", 
"auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined" FROM 
"auth_user"; args=()
(0.000) SELECT "auth_user"."id", "auth_user"."password", 
"auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", 
"auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", 
"auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined" FROM 
"auth_user" ORDER BY "auth_user"."date_joined" ASC LIMIT 1; args=()

This is a new install with only one user.  Your numbers are likely to be much 
higher and have significant differences.


> On Feb 12, 2021, at 5:50 PM, Peter of the Norse  wrote:
> 
> bool(qs) is recommended when the queryset has already been run.  If you do 
> something like 
> 
> val = qs.earliest(some_property) if bool(qs) else None
> 
> then there isn’t a performance gain because it still has to run qs.exists() 
> to even see if there is a value.  Later things like that will be cached 
> though.
> 
> Although I might be wrong about this.  I have not dug enough to be certain.
> 
>> On Jan 12, 2021, at 4:10 AM, 'Juergen H' via Django users 
>> mailto:django-users@googlegroups.com>> wrote:
>> 
>> Dear django users,
>> 
>> when working on very large datasets (millions of items) and performing 
>> queries on it, I have a few questions regaring the performance.
>> 
>> From my understanding using `bool(qs)` is preferred over using `qs.exists()` 
>> when the queryset is used later on, as `bool(qs)` already evaluates and 
>> caches the qs, which `qs.exists()` does not. Is that correct?
>> 
>> Is the above assumption also true, when the qs that has bee evaluated by 
>> using `bool(qs)` afterwards is accessed by e.g. 
>> `qs.earliest(some_property)`,? 
>> Or does `qs.earliest(some_property)` generate a new qs and hence there is 
>> not really an advantage of having the original qs already evaluated by 
>> `bool(qs)`?
>> 
>> E.g. using `.filter()` will surely create and return a new qs, as stated in 
>> the docu and in this case I am pretty sure, the advantage of evaluating and 
>> caching the qs by using `bool(qs)` is lost here.
>> But for `earliest()` or `latest()` the docu only states, that an object is 
>> returned. It does not say anything about a new queryset being created.
>> Hence my questions..
>> 
>> Thanks a lot and happy coding
>> Juergen
>> 
>> -- 
>> 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 
>> <mailto:django-users+unsubscr...@googlegroups.com>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/571d5cb6-bd53-4db4-aad1-2a820d71782en%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/571d5cb6-bd53-4db4-aad1-2a820d71782en%40googlegroups.com?utm_medium=email&utm_source=footer>.
> 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/23A6B39A-97B8-4CF7-9CAF-B45BD6B09B35%40gmail.com.


Re: What values is expected for CSRF_COOKIE_PATH ?

2021-03-08 Thread Peter of the Norse
Some sites have Django installed in a sub-path of their site, e.g. 
http://mydomain.com/django/.  In that case, you can set it to 
“/django-project/“ or “/“.  Since the default is / you don’t need to do 
anything.  If you have two separate Django installations on one site, then you 
need to change it because the two CSRF tokens will have different values.

> On Jan 29, 2021, at 6:46 AM, akash tyagi  wrote:
> 
> This should either match the URL path of your Django installation or be a 
> parent of that path. 
> This sentence is confusing to me. 
> 
> Suppose my domain name is demo.com , and I have django apps as App1,App2. 
> Both uses CSRF token. What should be the correct CSRF_COOKIE_PATH here ?
> 
> 
> 
> -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/5ed1519e-436b-4a65-9c8f-d89b3545b069n%40googlegroups.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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/42909D0B-287A-4706-A69D-FD0E23C0710F%40gmail.com.


Re: QuerySet performance on large datasets

2021-02-12 Thread Peter of the Norse
bool(qs) is recommended when the queryset has already been run.  If you do 
something like 

val = qs.earliest(some_property) if bool(qs) else None

then there isn’t a performance gain because it still has to run qs.exists() to 
even see if there is a value.  Later things like that will be cached though.

Although I might be wrong about this.  I have not dug enough to be certain.

> On Jan 12, 2021, at 4:10 AM, 'Juergen H' via Django users 
>  wrote:
> 
> Dear django users,
> 
> when working on very large datasets (millions of items) and performing 
> queries on it, I have a few questions regaring the performance.
> 
> From my understanding using `bool(qs)` is preferred over using `qs.exists()` 
> when the queryset is used later on, as `bool(qs)` already evaluates and 
> caches the qs, which `qs.exists()` does not. Is that correct?
> 
> Is the above assumption also true, when the qs that has bee evaluated by 
> using `bool(qs)` afterwards is accessed by e.g. 
> `qs.earliest(some_property)`,? 
> Or does `qs.earliest(some_property)` generate a new qs and hence there is not 
> really an advantage of having the original qs already evaluated by `bool(qs)`?
> 
> E.g. using `.filter()` will surely create and return a new qs, as stated in 
> the docu and in this case I am pretty sure, the advantage of evaluating and 
> caching the qs by using `bool(qs)` is lost here.
> But for `earliest()` or `latest()` the docu only states, that an object is 
> returned. It does not say anything about a new queryset being created.
> Hence my questions..
> 
> Thanks a lot and happy coding
> Juergen
> 
> -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/571d5cb6-bd53-4db4-aad1-2a820d71782en%40googlegroups.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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/A7EACE25-ABE9-44CA-8BAB-65E7953B5B71%40gmail.com.


Re: How to securely store passwords used in backend code

2021-01-10 Thread Peter of the Norse
I use multiple settings.py files to do this.  Specifically, in my main one, I 
have what I consider the only acceptable instance of import *.

import os
if (os.getenv('PRODUCTION')):
from .prod_settings import *
else:
from .dev_settings import *

While dev_settings.py is in my repo, prod_settings.py is not. 

If there are settings that are used in different systems/programs, 
https://pypi.org/project/python-dotenv/ 
 looks like the best choice.  Like 
Pankaj Jangid using Docker, and wants the same values in two places.

> On Dec 14, 2020, at 9:03 PM, David Nugent  wrote:
> 
> 
> On 10 December 2020 at 01:18:16, Pankaj Jangid (pan...@codeisgreat.org 
> ) wrote:
> 
>> Fenrir Sivar mailto:fenrir.si...@gmail.com>> 
>> writes: 
>> 
>> > I inherited a django app that calls private APIs in a view to fetch some 
>> > data. The credentials or api keys are currently hardcoded in the source, 
>> > making it difficult to share. 
>> > What is the preferred way to store these kind of keys in a secure way only 
>> > accessible to the django server? 
>> 
>> As Kasper suggests, I also use environment variables in development 
>> environment. But a few more things add up to convenience. 
> 
> Not only convenience, but a very good idea. First and foremost, keep secrets 
> out of configuration even gitignore'd ones, with .env files being the 
> exception.
> 
> The environment is not a perfect place to store these but they are better 
> then placing them in code or configuration.
> 
> For more info and a very tried and tested approach, check out 
> https://12factor.net/ 
> 
>> 1. I use ‘direnv’ for managing per directory environment variables. As I 
>> enter a perticular directory (on terminal), it echos the newly set 
>> environment variables. 
> 
> Seconded ... and thirded!
> 
> If you use .env files you can even suck these in automatically, set your 
> virtualenv and any configuration information in your .envrc. It is a really 
> good approach especially so i you work on multiple projects and don't want to 
> clutter your .*profile or Windows global env.
> 
> 
> 
>> 2. It might be overkill but I use Docker on my development machine. And 
>> I use the same environment variables in my docker-compose.yml. This 
>> is also useful in production setup where you are deploying in Docker. 
>> 
> 
> I would argue that this is definitely NOT an overkill unless you're entirely 
> unfamiliar with container technology when it would become another burden in 
> the path to understanding.
> 
> Running your code in a container when it is to be deployed in production in a 
> container is very important to avoid pitfalls such as local dependencies of 
> all sorts. "it works here" but fails in production is definitely something 
> you want to avoid.  You can mount your development environment locally and 
> run the server within the container and all is good, although this does raise 
> some interesting challenges if you want to debug the server...
> 
> 
> 
> 
> -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CAPvfA9A1zjp76qNf%2BN0QgacHuSzT0LQ246hFHoJCb7Bj1m1tYg%40mail.gmail.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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8367868B-70EC-47EF-A04B-702A48B23F63%40gmail.com.


Re: ForeignKey with different queryset from manager

2021-01-10 Thread Peter of the Norse
This is an interesting question.  Thank you for asking it.

I wasn’t able to find exactly what you are asking for.  The closest I could 
find was 
https://docs.djangoproject.com/en/2.2/topics/db/queries/#using-a-custom-reverse-manager
 

 which needs to be invoked at the call.  So you you have to do. 

parent.member_set(manager=‘all_objects').all()

> On Dec 14, 2020, at 3:25 PM, Jimmy Gawain  wrote:
> 
> This is with Django v2.2.
> 
> We use tombstoning via a custom BaseModelManager to mark items as deleted in 
> the database but keep them around for reference.
> 
> class BaseModelManager(models.Manager):
> def __init__(self, *args, **kwargs):
> self.include_tombstoned = kwargs.pop('include_tombstoned',False)
> super(BaseModelManager, self).__init__(*args, **kwargs)
> 
> def get_queryset(self):
> if not self.include_tombstoned:
> return TombstonedQuerySet(self.model).filter(is_tombstoned=False)
> return TombstonedQuerySet(self.model)
> 
> class BaseModel(models.Model):
> def __init__(self, *args, **kwargs):
> super(BaseModel, self).__init__(*args, **kwargs)
> 
> # manager
> objects = BaseModelManager()
> all_objects = BaseModelManager(include_tombstoned=True)
> 
> This way models can reference Model.objects when they want undeleted items 
> and Model.all_objects when they want to included deleted items.
> 
> We now have a situation where we want a ForeignKey, which uses objects, to 
> use all_objects instead.
> 
> That is instead of this:
> 
> ref_member = models.ForeignKey(Member, related_name='+', null=True, 
> blank=True, on_delete=models.CASCADE)
> 
> Do something like this:
> 
> ref_member = models.ForeignKey(Member, queryset=Member.all_objects.all(), 
> related_name='+', null=True, blank=True, on_delete=models.CASCADE)
> 
> Is there any way to do the equivalent of this?
> 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/4ee488b1-3489-430d-b917-70c157b35a92n%40googlegroups.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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/942B9218-D8BE-47B3-A0E2-789E39633A37%40gmail.com.


Re: How to access using foreing key

2020-12-13 Thread Peter of the Norse
If you are looking for all of the Restaurants with a 5.0 rating, it looks like

Restaurant.objects.filter(rating_restaurant__rating = 5.0)

If you are looking for Restaurants with an average rating of 5.0, that’s a bit 
trickier.

from django.db.models import Avg
Restaurant.objects.annotate(avg_rating = 
Avg('rating_restaurant__rating')).filter(avg_rating__eq = 5.0)

You can find some surprisingly relevant examples at 
https://docs.djangoproject.com/en/2.2/topics/db/aggregation/#order-of-annotate-and-filter-clauses
 
.

> On Oct 30, 2020, at 9:52 AM, Ashutosh Mishra  
> wrote:
> 
> class User(models.Model):
> name=models.CharField(max_length=50,blank=True,null=True)
> latitude = models.CharField('Latitude', max_length=30, blank=True, null=True)
> longitude = models.CharField('Longitude', max_length=30, blank=True, 
> null=True)
> location = models.PointField(blank=True, null=True)
> 
> def __str__(self):
> return str(self.name)
> 
> class Restaurant(models.Model):
> restaurant_name=models.CharField(max_length=50,blank=True,null=True)
> latitude = models.CharField('Latitude', max_length=30, blank=True, null=True)
> longitude = models.CharField('Longitude', max_length=30, blank=True, 
> null=True)
> location = models.PointField(blank=True, null=True)
> 
> def __str__(self):
> return str(self.restaurant_name)
> 
> 
> class RestaurantRating(models.Model):
> user = 
> models.ForeignKey(User,on_delete=models.CASCADE,null=True,related_name="customer_rating")
> restaurant = models.ForeignKey(Restaurant, on_delete=models.CASCADE, 
> null=True, related_name="rating_restaurant")
> rating = models.FloatField()
> 
> def __str__(self):
> return str(self.user)
> 
> How can i filter the restaurants whose rating is 5,Restaurant.objects.filter()
> 
> -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/cdaa9adf-5b4e-4de7-9c9d-f9e875e17acbn%40googlegroups.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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/A7CC40B1-C3AB-4744-85F7-4CD7CB6454C7%40gmail.com.


Re: NoReverseMatch at /sitemap.xml

2020-03-04 Thread Peter of the Norse
You are using positional arguments when you should be using named args.  Change 
the line to

return reverse('blog-detail', kwargs = {‘slug’:item.slug, 
‘year’:str(item.blog_published_at.year), 
‘month’:str(item.blog_published_at.month), 
‘day’:str(item.blog_published_at.day)})


> On Feb 22, 2020, at 9:00 AM, Yash Garg  wrote:
> 
> Please help me to resolve this issue. 
> 
> On Wednesday, February 19, 2020 at 10:13:07 PM UTC+5:30, Yash Garg wrote:
> When i'm loading sitemap.xml for my site i'm getting this error 
> 
> Reverse for 'blog-detail' with arguments '('This is my title slug', '2020', 
> '2', '19')' not found. 1 pattern(s) tried: 
> ['blog\\/(?P[0-9]+)\\/(?P[0-9]+)\\/(?P[0-9]+)\\/(?P[-a-zA-Z0-9_]+)$']
> 
> sitemap.py 
> 
> class BlogSitemap(Sitemap):
> priority = 0.5
> changefreq = 'daily'
> 
> def  items(self):
> return Blog.objects.filter(status=1)
> 
> def location(self, item):
> return reverse('blog-detail', args = (item.slug, 
> str(item.blog_published_at.year), str(item.blog_published_at.month), 
> str(item.blog_published_at.day)))
> 
> Models.py
> class Blog(models.Model):
> 
> STATUS = (
> (0,"Draft"),
> (1,"Publish")
> )
> 
> blog_title = models.CharField(_("Blog Title For Slug"), 
> validators=[MinLengthValidator(8)], max_length=120, blank=False,null=False)
> title = models.CharField(_("Blog Title"), 
> validators=[MinLengthValidator(8)], max_length=120, blank=True,null=False)
> slug = models.SlugField(_("Slug"), max_length=200, unique = True, blank = 
> True)
> meta_tag = models.TextField(_("Blog Meta tags"), null = False, blank= 
> True)
> banner_text = models.CharField(_("Top Banner Text Overlay"), max_length = 
> 50, null = False)
> banner_image = models.FileField(_("Banner Image"), blank=True)
> blog_abstract = models.TextField(_("Blog Abstract"), max_length= 500, 
> blank = False, null = False)
> blog_published_at = models.DateField(_("Blog published date") , blank = 
> False, default = timezone.now)
> blog_image = models.FileField(_("Blog Image"), blank=True)
> def __str__(self):
> return self.title
> 
> class Meta:
> ordering = ['-blog_published_at']
> db_table = '"public_blog"'
> 
> def get_absolute_url(self):
> return reverse('blog-detail', args=(self.slug, 
> self.blog_published_at.year, self.blog_published_at.month, 
> self.blog_published_at.day))
> 
> def save(self):
> super(Blog, self).save()
> self.slug = slugify(self.blog_title)
> super(Blog, self).save()
> urls.py 
> 
> path('sitemap.xml', sitemap, {'sitemaps':sitemaps}, name = 'sitemap'),
> 
> How can i resolve this issue?
> 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/7afdb4f4-ac77-4495-b558-9042fd70cf29%40googlegroups.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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/E9205793-4D2C-403B-BBF9-AD0A397B4BE5%40gmail.com.


Re: Why use CustomUserManager.create_user and not CustomUserManager.create?

2019-03-14 Thread Peter of the Norse
The biggest difference is that when you call create_user, it creates a hash of 
the password.  Eventually, create_user does call create, but only after setting 
all the values properly.

Sent from my iPad

> On Feb 17, 2019, at 4:30 AM, Maarten Nieber  wrote:
> 
> Hi,
> 
> the Django guidelines tell us to implement CustomUserManager.create_user. 
> However, this seems to introduce some ambiguity between
> CustomUserManager.create_user and CustomUserManager.create, since both these 
> methods can be expected to create a User. In fact,
> it would be easy to accidentically call the wrong method from source code.
> 
> Is there any reason why the create_user function exists at all? Why doesn't 
> Django tell us to override CustomUserManager.create?
> 
> Or alternatively, I could imagine that Django could have a hook function that 
> is called by CustomUserManager.create, where the hook can be used
> to implemented custom behaviour (so that at least we have only 1 function to 
> create users). Would this be a better design? Or is the current
> design the correct one, and am I missing something? (in that case, please 
> elaborate)
> 
> Best regards,
> Maarten
> 
> 
> -- 
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/b934b1a4-a295-4e83-be9c-b787785e5fc6%40googlegroups.com.
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/E560F7DD-84E1-485F-92E4-D89E9240188D%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How 2 access the Primary model's ID in the Foreign model??

2018-12-31 Thread Peter of the Norse
Also song.album_id will work as well, and faster too.

Sent from my iPad

> On Dec 4, 2018, at 3:43 PM, Mike Dewhirst  wrote:
> 
>> On 5/12/2018 7:07 AM, Sourajit Mohanty wrote:
>> I have 2 model classes Album and Songs(where Song is the Foreign key)
>> I want to access the Albums ID in the Songs class..
>> How can I do that??
>> 
> 
> 
> song = Songs.objects.get(name='Happy birthday')
> albumid = song.album.id
> 
> Similarly ...
> 
> album = song.album
> 
> This assumes your model code in Songs names the foreign key 'album'
> 
> -- 
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/d7e6a11e-e55d-3393-6937-31dee72d4035%40dewhirst.com.au.
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/02EB60C5-DA5F-4D9B-9FFC-3797470F8226%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: about unique_together

2018-12-13 Thread Peter of the Norse
Django doesn’t support multiple primary keys.  unique_together just adds an 
extra constraint to the table.

Since you didn’t specify a primary key, id was added for you by default.  

Sent from my iPad

> On Nov 14, 2018, at 1:55 AM, 胡超  wrote:
> 
> 
> class QdProjectAssist(models.Model):
> '''
> 页面推荐
> '''
> # id = models.AutoField('主键', primary_key=True)
> project_id = models.ForeignKey('QdProject', verbose_name='项目', 
> on_delete=models.CASCADE)
> assist_id = models.ForeignKey('QdAssist', verbose_name='正文', 
> on_delete=models.CASCADE)
> sort = models.PositiveIntegerField('排序', blank=True, null=True)
> addtime = models.PositiveIntegerField('添加时间')
> uptime = models.DateTimeField('更新时间', auto_now=True)
> 
> class Meta:
> managed = False
> db_table = 'qd_project_assist'
> unique_together = ('project_id', 'assist_id')
> verbose_name = '页面推荐'
> verbose_name_plural = verbose_name
> 
> I export the table with two primary keys from mysql.
> 
> Reporting errors in the course of use
> 
> django.db.utils.InternalError: (1054, "Unknown column 'qd_project_assist.id' 
> in 'field 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/117bd094-09bd-429c-a289-0074de2374f5%40googlegroups.com.
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8E2B53CE-4BBD-4531-A7EB-AEDF6C428BAF%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Field.choices get all items as json

2018-05-20 Thread Peter of the Norse
Create a view that returns json.  At least if you want to use it in an ajax 
way.  Otherwise, I would recommend just passing it as an argument to the 
templates that use it.

import json

def years(request):
return HttpResponse(json.dumps(dict(Model.YEAR_IN_SCHOOL_CHOICES)), 
content_type=‘application/json')

The dict is there to make sure you get it as an object instead of an array of 
arrays.

> On May 18, 2018, at 1:20 AM, Majid Hojati  wrote:
> 
> In fact I want to convert all of these choises into json format and then send 
> them to user 
> thanks
> 
> On Thursday, May 17, 2018 at 8:46:42 PM UTC+4:30, C. Kirby wrote:
> if you just want to put that into json do:
> import json
> 
> YEAR_IN_SCHOOL_CHOICES = (
> ('FR', 'Freshman'),
> ('SO', 'Sophomore'),
> ('JR', 'Junior'),
> ('SR', 'Senior'),
> )
> 
> serialized_year_choices = json.dumps(Model.YEAR_IN_SCHOOL_CHOICES) 
> 
> 
> 
> 
> 
> On Thursday, May 17, 2018 at 10:52:15 AM UTC-4, Majid Hojati wrote:
> Hi,
> I have a Field.choices in my model. lets say it is:
> 
> YEAR_IN_SCHOOL_CHOICES = (
> ('FR', 'Freshman'),
> ('SO', 'Sophomore'),
> ('JR', 'Junior'),
> ('SR', 'Senior'),
> )
> 
> I can access them using this method Model. YEAR_IN_SCHOOL_CHOICES  but how 
> can I convert it to a json then I can send them using a webservice ? is there 
> any good method?
> 
> -- 
> 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 https://groups.google.com/group/django-users 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/be3eabf9-939a-429f-a7c8-62ba30b98981%40googlegroups.com
>  
> .
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1CF3C717-1324-48CF-B9D2-6A62A3EFF827%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Decorator function argument woes

2018-05-07 Thread Peter of the Norse
Yes, but that’s because all of the arguments are optional.  That way you can do:

@login_required
def my_view(request):
…

@login_required(login_url=“/login/“)
def other_view(request):
…

- Peter of the Norse

> On Apr 30, 2018, at 12:24 AM, Mike Dewhirst  wrote:
> 
>> On 30/04/2018 3:35 PM, Stephen J. Butler wrote:
>> @login_required doesn't take a test function. You need to use 
>> @user_passes_test directly.
> 
> Thank you Stephen.
> 
> I thought I'd start another thread to ask about my use case of being able to 
> require login or not depending on whether the content needed a login or not 
> ... but ... just as I was thinking about it I had another look at 
> login_required and thought I'd ask one more question.
> 
> Its signature is ...
> 
> def login_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME, 
> login_url=None):
> 
> Are you saying that function is the the view function?
> 
> M
> 
>> 
>> On Mon, Apr 30, 2018 at 12:26 AM, Mike Dewhirst > <mailto:mi...@dewhirst.com.au>> wrote:
>> 
>>I'm pretty sure this is a not-understanding-python problem rather
>>than a Django problem but here goes ...
>> 
>>In a (FBV) view I'm trying to pass a function in to the
>>login_required decorator. My function is called 'is_login_needed'
>>and I want the login_required decorator to effectively switch
>>itself off if login is not needed.
>> 
>>The scenario is on-line training and if the training instruction
>>has questions with scores then obviously the user needs to login.
>>On the other hand if it is simply a demonstration video or plain
>>blah with no questions/answers/scores it should be viewable by
>>anyone whether they are logged in or not.
>> 
>>My function goes like this and the docstring reveals my
>>understanding ...
>> 
>>def is_login_needed(user):
>> 
>>""" the login_required decorator has a user_passes_test()
>>function as
>> 
>>its first arg. If it returns True, no login is required.
>>user.login_here
>> 
>>is always set equal to the selected course.login_needed. For
>>courses
>> 
>>needing a login, self.is_authenticated must be True. For
>>courses not
>> 
>>needing a login, self.is_authenticated may return anything but
>>this
>> 
>>function passed to the login_required decorator must return True
>> 
>>"""
>> 
>>if not user.login_here:
>> 
>>return True
>> 
>> 
>>So   the problem is that manage.py runserver reports an attribute
>>error saying the function (presumably mine) does not have an
>>attribute 'user' ... like this ...
>> 
>>   File
>>"C:\Users\mike\envs\xxct3\train\course\urls.py", line 8, in 
>> 
>>from .views import (finished_course_view, course_view, index_view,
>> 
>>  File "C:\Users\mike\envs\xxct3\train\course\views.py", line 172,
>>in 
>> 
>>def course_view(request, pk=None, slug=None):
>> 
>>  File
>>
>> "C:\Users\mike\envs\xxct3\lib\site-packages\django\contrib\auth\decorators.py",
>>line 22, in _wrapped_view
>> 
>>if test_func(request.user):
>> 
>>AttributeError: 'function' object has no attribute 'user'
>> 
>>If that 'function' is my 'is_login_needed' function I'm inclined
>>to think it obviously has a 'user' attribute.
>> 
>>Here is the contrib.auth.decorators.login_required source
>>(preceded by user_passes_test which it calls) from Django 1.11
>> 
>>My reading of the following  is that my own 'is_login_needed'
>>function passed in via @login_required(is_login_needed,
>>login_url='login') as the first positional argument is then passed
>>to the 'user_passes_test' decorator as 'test_func'  ...
>> 
>> 
>>def user_passes_test(test_func, login_url=None,
>>redirect_field_name=REDIRECT_FIELD_NAME):
>> 
>>"""
>> 
>>Decorator for views that checks that the user passes the given
>>test,
>> 
>>redirecting to the log-in page if necessary. The test should
>>be a callable
>> 
>>that takes the user object and returns Tr

Re: unexpected JSONField behavior clarification - key value pairs initially loaded integers, then saved down as strings into the database

2018-05-06 Thread Peter of the Norse
This is actually part of the JSON specification 
<https://tools.ietf.org/html/rfc7159#section-4>.  All of the keys must be 
strings.  If you put in an int or float, it will automatically convert it, but 
that is something you have to watch out for since it can lead to data loss.

>>> import json
>>> test = {4: 5, '4': 'a'}
>>> json.loads(json.dumps(test))
{'4': 5} 

> On Apr 24, 2018, at 6:06 PM, Oliver Zhou  wrote:
> 
> Using Django 1.11, Python 2.7, PostGres, and JSONField I'm getting behavior I 
> don't expect.
> 
> It seems when JSONField values are initially saved/accessed in memory, 
> they're python "integers", but when saved to the database and then 
> re-accessed, the values are now in string format.
> 
> What about how Django handles JSONField string vs integers am I missing here? 
> Whats the best way to get deterministic behavior here? 
> Am I supposed to always, say, use json.dumps to work with this stuff in 
> string format? Should I be converting all JSONField values before trying to 
> access any values?
> 
> Example 1 - Basic Problem
> 
> Example Model :
> class ExampleModel(models.Model): 
> external_ids = JSONField(blank=True, null=True, default=dict)
> 
> My code:
> new_example = ExampleModel.objects.create()
> new_example.external_ids[1234] = {}
> print(new_example.external_ids)
> 
> Output looks like this : 
> {1234: {}}
> 
> 
> I can now access values stored like this :
> In [140]: new_example.external_ids[1234]
> Out[140]: {}
> 
> I will now then save the object to the database
> new_example.save()
> 
> However, when I go back and try to access the fields again, all integer 
> values in the JSON have been converted into strings, and I cannot access them 
> anymore without getting a KeyError
> reload_example = ExampleModel.objects.get(id=1) 
> reload_example.external_ids[1234] 
> In [144]: reload_example.external_ids[1234]
> ---
> KeyError  Traceback (most recent call last)
>  in ()
> > 1 reload_example.external_ids[1234]
> KeyError: 1234
> 
> 
> By this time, the integer 1234 has been converted into a string that looks 
> like something like the following :  Why is this?
> In [147]: print(reload_example.external_ids)
> Out[147]: {u'1234': {}}
> 
> Therefore, at this time, I have to do this to access the fields : Whats the 
> correct way to handle this?
> In [160]: c2.external_ids[str(1234)]
> Out[160]: {}
> 
> Example 2 - Non-deterministic Merge Problem - 
> In fact, this creates some other interesting problems for me too, where 
> integer keys and string keys get merged together in uncertain order as well.
> 
> I create a new model - and save some key value pairs down into the JSONField:
> In [164]: example2 = ExampleModel.objects.create()
> In [165]: example2.external_ids
> Out[165]: {}
> In [166]: example2.external_ids[1234] = {'567': '890'}
> In [167]: example2.save()
> In [169]: example2.external_ids
> Out[169]: {1234: {'567': '890'}}
> 
> Then I try to reload the model back into memory :
> 
> In [170]: reload_example2 = ExampleModel.objects.get(id=2)
> In [171]: reload_example2.external_ids
> Out[171]: {u'1234': {u'567': u'890'}}
> 
> Then I try to save a new set of values for key 1234:
> 
> In [172]: reload_example2.external_ids[1234] = {'890': '567'}
> In [173]: reload_example2.external_ids
> Out[173]: {1234: {'890': '567'}, u'1234': {u'567': u'890'}}
> 
> Now it seems like both key value pairs are loaded into memory - just the 
> older one is tracked by a string-ified key, and the new values are tracked by 
> an integer-based key
> In [174]: reload_example2.save()
> 
> Then I save and reload the model again - it seems uncertain which values 
> actually got saved down - whats the expectation here?
> In [175]: reload_example3 = ExampleModel.objects.get(id=2)
> In [176]: reload_example3.external_ids
> Out[176]: {u'1234': {u'890': u'567'}}
> 
> 
> Thanks!
> Oliver
> 
> -- 
> 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 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com 
> <mailto:django-users@googlegroups

Re: Use self-increasing arguments in numeric for-loop in Django

2018-05-03 Thread Peter of the Norse
First of all, this is a terrible idea.  You should fix up graphobject in your 
view to do what you want, not try to massage it in your template.

Second, you can’t use template tags inside a template.  That’s not how it works 
at all.

Third, you are not the first to have this terrible idea.  You can search the 
web and find many examples of people “solving” this non-problem.

- Peter of the Norse

> On Apr 20, 2018, at 7:49 AM, Bill Torcaso  wrote:
> 
> 
> I an new-ish to Django, and I ask this to hear from more experienced users 
> whether this would work at all, and whether it would be considered a good or 
> bad practice.
> 
> Goal: given an object and an integer index, retrieve the sub-object at that 
> index within the incoming object.
> 
> Method:  Write a custom tag.  Provide the tag with the larger object, and the 
> integer index.  Return the sub-object at that index (or whatever field(s) are 
> needed).
> 
> Usage:
> 
>   {% for i in metarange %}
> {% graphobject_get_by_index graphobject {{ i }} %}
>   {% endfor %}
> 
> 
> In this particular case, there is an issue about whether the sub-object can 
> be null, for some definition of null.  There are various ways to deal with 
> that.
> 
> Again, I am new-ish to Django.  Is there a similar approach in which 
> 'get_by_index' is a method on class Graphobject, such that this would work?
> 
> {% graphobject.get_by_index {{ i }} %}
> 
> Thanks for any explanation about these approaches.
> 
> 
>> On Thursday, April 19, 2018 at 12:01:37 PM UTC-4, shaw...@gmail.com wrote:
>> I am currently working on django.
>> 
>> I have a list of values which stored in 'graphobject', and 'metarange' is 
>> defined as range(0,59). In that case, how could I use numbers as argument to 
>> display the value stored in graphobject? I tried using following codes but 
>> it doesn't work
>> 
>> 
>> 
>> {% for i in metarange %}
>> {% if graphobject.i != '' %}
>> {{ graphobject.i }}
>> {% endif %}
>> {% endfor %}
>> 
>> 
>> Please tell me how could I do this?
>> 
> 
> -- 
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/9c162dd2-201b-4370-bac0-f3afb3db163a%40googlegroups.com.
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5A9432AF-BA0B-47C5-BF9F-DA4A5DDDB259%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: chemistry character set

2018-03-15 Thread Peter of the Norse
I ran into a similar problem with one of my projects; people were using Greek 
and Cyrillic letters and other symbols to be cute.  It’s all in English, but 
they kept doing things like using ß for B and ¥ for Y.  And then expecting to 
be able to search the way they way it looks.  So I am doing the cleanup in the 
.save() method.  My only advice is to use 
https://docs.python.org/3/library/stdtypes.html?highlight=translate#str.translate
 instead of multiple replaces.  If you make the translation map a global 
variable, it is much faster. 

- Peter of the Norse

> On Feb 15, 2018, at 5:55 AM, Mike Dewhirst  wrote:
> 
>> On 15/02/2018 10:19 PM, Hanne Moa wrote:
>>> On 2018-02-06 12:51, Mike Dewhirst wrote:
>>> Thank you. I think this is where we probably need to go. I asked the 
>>> original question because I'm hoping the project will reach a tipping point 
>>> and start to accumulate a growing number of multilingual users. We have our 
>>> first multinational user but they only operate in the English speaking 
>>> world so no pressure at the moment.
>> There can be no sort that satisfies every possible language at the same 
>> time. For instance, Norwegian sorts "ä" as "a" and "ö" as "o". Swedish sorts 
>> them after "å" as separate letters: åäö. Then there is Turkish where "i" 
>> sorts differently from "ı" (dotless i).
> 
> That is interesting! It says to me that longer term I need to think about 
> special sort orders for different languages. A bit above my pay grade just 
> now.
> 
> I've worked the greek letter prefixes by using a separate sort field only 
> seen by the software. A simple replace('α', 'a') lets me adjust sort order 
> for the moment. That may work with diacritics for some time. I'll be driven 
> by actual requirements until I hit a brick wall and then I'll ask for PhD 
> help :)
> 
> Thanks
> 
> Mike
> 
>> I'm guessing chemistry names follow their own rules, you could see how hard 
>> it is to make your own os collation table and use that? Then everything 
>> running on the server would sort by the same rules.
>> HM
>> 
> 
> -- 
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/bfd1633b-a651-fec9-6f2a-86efac8d2e8c%40dewhirst.com.au.
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/65B863CA-7C6C-4DC7-83FC-DAE87D2F6E8C%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Migrating into Django 1.9; question about autoescape

2018-03-11 Thread Peter of the Norse
This seems odd, because autoescaping has been on since almost the beginning.  
https://web.archive.org/web/20080826081214/http://docs.djangoproject.com:80/en/dev/topics/templates/#id2
  What actually changed with 1.9?

> On Feb 13, 2018, at 7:53 AM, Bill Torcaso  wrote:
> 
> 
> Hello all,
> 
> I have the task of migrating a very old website from Django 1.7 to either 
> Django 1.11 or 2.0, depending on the effort.
> 
> My plan is to go from 1.7 --> 1.8 --> 1.9 -->1.10 --> 1.11, adapting the 
> codebase as I go.  It's been easy enough until I arrive at 1.9, and the 
> change in template-rendering in which "autoescape" defaults to "on".
> 
> Now a lot of my payload is arriving at the browser with my HTML tags escaped. 
>  For example,
> 
>gets rendered as<button>
> 
> I have no argument with the autoescape-on default setting.  But I am unsure 
> how to proceed, and how large the effort will be.  As background, I am a 
> seasoned back-end programmer and a lightweight in HTML and template issues.
> 
> I see these alternatives.  Are there any others?
> 
> Get to the Template Engine object and set its autoescape attribute to "off".  
> This loses the protection that autoescape-on provides, restores the Django 
> 1.8 behavior, and let me proceed with the smallest amount of effort.
> 
> Is this the template engine I need?  "django.core.context_processors.request" 
>  And how do I get to the object?
> 
> Visit all of my HTML files and put "{% autoescape off %}" everywhere.
> 
> I put "{% autoescape off %}" in my base.html, and it partially solved the 
> problem.  But it did not get everything.
> 
> This is a medium amount of effort, and if I make a mistake the users will 
> have a bad experience.
> 
> Visit all of my code and all of my templates, carefully converting into the 
> world of autoescape-on.
> Thanks in advance,
> 
>   ---  Bill Torcaso

Peter of the Norse
rahmc...@radio1190.org



-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/41307A5D-0AEB-4EAF-A9E9-DE93739A1281%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: django mathfiters

2018-02-27 Thread Peter of the Norse
I would do
{% with a=42 c=b.value|default_if_none:0}

- Peter of the Norse

> On Feb 21, 2018, at 3:47 PM, Matthew Pava  wrote:
> 
> And how are you checking if it’s None?  I would do it like this:
> {% if c %}
> {{ a|add:c }}
> {% else %}
>   {{ a }}
> {% endif %}
>  
> From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
> Behalf Of sum abiut
> Sent: Wednesday, February 21, 2018 4:43 PM
> To: django-users@googlegroups.com
> Subject: Re: django mathfiters
>  
> Thanks for your response. Yes the value was actually None. how to i display 
> 42  instead of not displaying anything at all. I have try using the if 
> statement to check for the value of c if its None i just display the value of 
> a, and if is not None i add the values. But still its displaying nothing.
>  
> Thanks
>  
> On Thu, Feb 22, 2018 at 9:15 AM, Matthew Pava  wrote:
> Check the value of b.value.  Make sure it isn’t None.
>  
> From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
> Behalf Of sum abiut
> Sent: Wednesday, February 21, 2018 4:06 PM
> To: django-users@googlegroups.com
> Subject: django mathfiters
>  
>  
> Hi,
> How to you a zero in mathfilter
> for example, if the value of c is zero the total is not display. instead of 
> displaying 42 it display nothing.
>  
> {%for b in pay%}
> {% with a=42 c=b.value%}
>  {{ a|add:c }}
> {% endwith %}
> 

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8C4DDEF6-9168-4181-B5DD-8E37AB487685%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Django Http request question.

2018-01-21 Thread Peter of the Norse
There are a bunch of things going on here that aren’t Django questions.  First 
of all, Twilio is a service that connects SMS (or text messages) to your 
server.  This blog post is for experienced Django users to help explain how you 
can use Twilio with your existing site, and not for people who are starting out.

The other questions are basic Python, and so I recommend you start with a 
tutorial.  The official one is at https://docs.python.org/3/tutorial/, but I 
don’t know if it’s the best.

- Peter of the Norse

> On Jan 17, 2018, at 8:32 PM, cherngyo...@gmail.com wrote:
> 
> I have been reading about django http request documentation but it is still 
> kinda too hard to understand it. 
> So i would like to ask these few questions based on the code at the bottom of 
> this website:
> https://www.twilio.com/blog/2014/11/build-your-own-pokedex-with-django-mms-and-pokeapi.html
> 
> This is the code in the website.
> 
> from django_twilio.views import twilio_view
> from twilio.twiml import Response
> import requests
> import json
> 
> BASE_URL = 'http://pokeapi.co'
> 
> def query_pokeapi(resource_uri):
> url = '{0}{1}'.format(BASE_URL, resource_uri)
> response = requests.get(url)
> 
> if response.status_code == 200:
> return json.loads(response.text)
> return None
> 
> @twilio_view
> def incoming_message(request):
> twiml = Response()
> 
> body = request.POST.get('Body', '')
> body = body.lower()
> 
> pokemon_url = '/api/v1/pokemon/{0}/'.format(body)
> pokemon = query_pokeapi(pokemon_url)
> 
> if pokemon:
> sprite_uri = pokemon['sprites'][0]['resource_uri']
> description_uri = pokemon['descriptions'][0]['resource_uri']
> 
> sprite = query_pokeapi(sprite_uri)
> description = query_pokeapi(description_uri)
> 
> message = '{0}, {1}'.format(pokemon['name'], 
> description['description'])
> image = '{0}{1}'.format(BASE_URL, sprite['image'])
> 
> frm = request.POST.get('From', '')
> if '+44' in frm:
> twiml.message('{0} {1}'.format(message, image))
> return twiml
> twiml.message(message).media(image)
> return twiml
> 
> twiml.message("Something went wrong! Try 'Pikachu' or 'Rotom'")
> return twiml
> 
> My question is these:
> 1. if i am just using django and django rest framework, it is not a must to 
> use this @twilio_view right ?
> 
> 2. I do not understand this part. What does request.POST.get() means? My own 
> understanding is that this is POST method with user input. And the .get part 
> is where u get the response after POST method
> But where is the user input ?
> 
> body = request.POST.get('Body', '')
> body = body.lower()
> 
> frm = request.POST.get('From', '')
> 
> 3. what does body.lower() means ?
> 
> 4. what does the 'sprites' means ? Is it one of the field that was display in 
> the API ? I did try doing a ctrl+F to check for sprites and descriptions but 
> not even 1 show up so im confuse. What does the [0] means ?
> 
>  sprite_uri = pokemon['sprites'][0]['resource_uri']
>  description_uri = pokemon['descriptions'][0]['resource_uri']
> 
> 5. the if '+44' in frm: means that if there consist of this '+44' string in 
> the API, then execute ?
>  frm = request.POST.get('From', '')
> if '+44' in frm:
> 
> 
> Sorry for these long question as i cant understand what they were explaining 
> in the documentation.
> -- 
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/195d9f0d-1fcb-449d-b6a1-1c7b49df6838%40googlegroups.com.
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/71FCCA02-D3A9-43F0-A218-E610D98DEC00%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: I can't install easy install

2018-01-09 Thread Peter of the Norse
This is the second time I’ve seen this and need to let you know it’s not true.  
PowerShell doesn’t have elevated permissions, it’s just bash for .NET.  While 
there are a bunch of new scripting features built into it, it has no effect on 
Python* or any other commands you might run.

- Peter of the Norse
> 
> It is probably best to avoid using Powershell unless you have a strong 
> preference. It gives you permissions which might lead you to developing 
> software which assumes it has those permissions. I might be wrong there but I 
> haven't had any difficulties using the ordinary shell.
> 
> Welcome Henry

*  This might not be true if you are running IronPython, but it was never 
updated to 3, so it doesn’t matter.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4D802920-3CC6-4F7B-B393-0203783D409C%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: [ORM Foreign Keys][Performance] How to use Charfield Foreign Keys efficiently?

2017-12-21 Thread Peter of the Norse
This should be a bug.  Most databases don’t even allow foreign keys to be a 
different type.  I didn’t see anything in the docs about this, but it should 
happen automatically.  There are several examples of using non-int fields, e.g. 
UUID.  Can you provide your migration file for OmEvent and model definition for 
CaseInfo2?

- Peter of the Norse

> On Nov 21, 2017, at 7:16 AM, Dominik Szmaj  wrote:
> 
> Hey,
> 
> 'case_id' is a monkeypatch number(*) field so it works quick for now, not a 
> pk, but unique:
> class OmEvent(Model):
> case = ForeignKey('CaseInfo2', to_field='case_id', related_name='events', 
> blank=True, null=True)
> 
> class Meta:
> db_table = 'om_event'
> 
> old form:
> class OmEvent(Model):
> case = ForeignKey('CaseInfo2', related_name='events', blank=True, 
> null=True)
> 
> class Meta:
> db_table = 'om_event'
> which points to 'case_number' pk which is a varchar.
> 
> Everything is managed by db router which prevents migrations on remote db.
> 
> Regards,
> Dominik
> 
> W dniu wtorek, 21 listopada 2017 15:00:49 UTC+1 użytkownik Avraham Serour 
> napisał:
>> 
>> can you post your model?
>> 
>>> On Tue, Nov 21, 2017 at 3:31 PM, Dominik Szmaj  wrote:
>>> Hey,
>>> 
>>> I have a very big performance problem with Django and Oracle db.
>>> 
>>> This legacy db has lots of primary keys as strings from the time when those 
>>> id's were alphanumerical so it can't be simply converted to number.
>>> 
>>> So when I set FK on such varchar column django seems to not crash but it 
>>> converts to int and search whole table of strings with a number which takes 
>>> ages to complete.
>>> 
>>> Is there maybe some sane solution to the problem? Why it forces me to use 
>>> numbers on varchar FK?
>>> 
>>> Best regards.
>>> Dominik
>>> -- 
>>> 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 https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/e4e51608-740c-410c-bc47-21d189c0edf6%40googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
> 
> W dniu wtorek, 21 listopada 2017 15:00:49 UTC+1 użytkownik Avraham Serour 
> napisał:
>> 
>> can you post your model?
>> 
>>> On Tue, Nov 21, 2017 at 3:31 PM, Dominik Szmaj  wrote:
>>> Hey,
>>> 
>>> I have a very big performance problem with Django and Oracle db.
>>> 
>>> This legacy db has lots of primary keys as strings from the time when those 
>>> id's were alphanumerical so it can't be simply converted to number.
>>> 
>>> So when I set FK on such varchar column django seems to not crash but it 
>>> converts to int and search whole table of strings with a number which takes 
>>> ages to complete.
>>> 
>>> Is there maybe some sane solution to the problem? Why it forces me to use 
>>> numbers on varchar FK?
>>> 
>>> Best regards.
>>> Dominik
>>> -- 
>>> 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 https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/e4e51608-740c-410c-bc47-21d189c0edf6%40googlegroups.com.
>>> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/a8512002-4fac-4ae0-b6ee-35a239d2670f%40googlegroups.com.
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/C2CCC001-3BEE-411B-9669-5D66C4A4DFEB%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic querysets?

2016-12-16 Thread Peter of the Norse
you are looking for `statedict.items()`.  (Or `statedict.iteritems()` on 
py2)  By default a dict just loops over the keys.  And then it unpacks 
your two letter string into k, v. So the first step of your loop is 
k='A' and v='K'.


Also, that's not how you use get.

On 12/16/2016 4:19 PM, Malik Rumi wrote:


|naively thinking I would be able to do something like|




|
fork,v instatedict:
iftwodigit ==k:
 state =Jurisdiction.objects.get(v)
|


--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8e9148a0-c090-c4ff-b29b-14a91efaaa23%40radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Django MongoEngine rest api app post request.POST.get('id')

2016-09-28 Thread Peter of the Norse
Are you doing request.POST.get(’taxi_id’) here?  Because that will return a 
string.  And in that case, id would be each letter in the actual ID.  Try 
switching it to request.POST.getlist(’taxi_id’).

> On Sep 27, 2016, at 9:43 AM, samer sarker  wrote:
> 
>  for id in taxi_id:
> taxi = TaxiMaster.objects(id=id).first()
> 
> temp = BookedTaxi(
> taxi_id=id,
> driver_id=taxi.user_id,
> is_seen=0,
> is_accepted=0,
> is_rejected=0
> )
> 
> 
> 
> 
> 
> 
> ValidationError at /action
> 
> u'5' is not a valid ObjectId, it must be a 12-byte input of type 'str' or a 
> 24-character hex string
> 
> 
> 
> how to solve this error
> 
> -- 
> 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 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com 
> <mailto:django-users@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users 
> <https://groups.google.com/group/django-users>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/57545fd3-2460-44ee-8988-079998523a54%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/57545fd3-2460-44ee-8988-079998523a54%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

Peter of the Norse
rahmc...@radio1190.org



-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2FE239C8-4A1A-4C3F-8B10-6B7DB2BEF693%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Format of arrays in multipart forms?

2016-09-27 Thread Peter of the Norse
PHP is stupid.  The problem with the [] syntax is that you have to be careful that the user hasn’t added or removed it from your fields.  This can cause problems if you were expecting an array and got a string, or vice-versa.Instead, name the fields without [], and in your Django code, use request.POST.getlist(‘array’).  That way you are assured to get a list no matter what values the user sent.On Aug 26, 2016, at 2:13 PM, ggil...@gmail.com wrote:I'm trying to create an iOS app that can post multipart forms to Django. (JSON is trivial, wish it worked with file uploads. :-)What is the proper format for the HTTP request when passing arrays of values? (Strings is all I care about at the moment)I think PHP has the follow style. What is the Django equivalent? I tried reading through the sources, but it wasn't obvious.Thanks,     Greg--Boundary-56A500AE-D543-43BD-93F0-6A1721A73F70Content-Disposition: form-data; name="array[]"one--Boundary-56A500AE-D543-43BD-93F0-6A1721A73F70Content-Disposition: form-data; name="array[]"two--Boundary-56A500AE-D543-43BD-93F0-6A1721A73F70Content-Disposition: form-data; name="array[]"three--Boundary-56A500AE-D543-43BD-93F0-6A1721A73F70

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4d999852-b1eb-4b39-bbb3-46606a77d0c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Peter of the Norserahmc...@radio1190.org






-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/E5274A19-D4D2-4BA2-9B47-469E92ED9DE9%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Query annotation with date difference

2016-09-04 Thread Peter of the Norse
I would use the DB NOW() function for this.  https://docs.djangoproject.com/en/1.9/ref/models/database-functions/#nowfrom django.db.models.functions import Now.annotate(ratio=(F(‘due_date')-Now())/F('Interval'))On Aug 3, 2016, at 3:34 PM, Constantine Covtushenko  wrote:Sorry, I did not specify.I have been using 'Postgresql' with 'psycopg2 v.2.6.2'.They gave me those results.Also here is a sql query given from log:SELECT "test_app_entity"."id", "test_app_entity"."due_date", "test_app_entity"."interval", (("test_app_entity"."due_date" - '2016-08-03T21:31:58.325549+00:00'::timestamptz) / "test_app_entity"."interval") AS "ratio" FROM "test_app_entity"; args=(datetime.datetime(2016, 8, 3, 21, 31, 58, 325549, tzinfo=),)That is all that I can say at the moment.On Thu, Aug 4, 2016 at 12:20 AM, Yoann Duriaud  wrote:Thanks, unfortunately not so great on my side:I added in the query (forgetting the division for now):.annotate(ratio=ExpressionWrapper(F('due_date')-timezone.now(), DateTimeField()))which leads to the following statement in the query: ("contentstatus"."due_date" - 2016-08-03 21:05:10.743799+00:00) AS "ratio"This is not a valid SQL statement (at least for SQLite) and leads to the following error message when the query is evaluated:Exception Type:TypeError




  Exception Value:
  expected string or bytes-like objectAny idea what I get this behavior?YoannLe samedi 30 juillet 2016 22:41:21 UTC+2, Yoann Duriaud a écrit :Hello,I would like to annotate a query with the following _expression_: ([Due Date] - [Now])/[Interval]. [Due Date] and [Interval] are fields from the database, while [Now] should be "equal" to timezone.now().So this would look like:.annotate(ratio=(F('due_date')-timezone.now())/F('Interval'))but this does not work. Does someone know how the _expression_ should be written (if it is indeed feasible with Django ORM)?Thanks for your help!Yoann

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/038837c5-6b5b-4ae9-895a-b6b54282d978%40googlegroups.com.
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK52boX3b%2Bb6okqsKVXX%3DxQ7HUss9qL_BRbL8rpWFGE%3Ds2xL9g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Peter of the Norserahmc...@radio1190.org






-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3520A304-1CF3-4569-8F73-033BD1D108E1%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Questions about Deploying django for production using apache and mod_wsgi.

2016-06-26 Thread Peter of the Norse
On May 26, 2016, at 12:12 PM, Bruce Whealton 
 wrote:
> 
> Hello all,
> I have a few questions of which I am not finding answers.
> 1) If I export my development db (Postgresql) and then import it into 
> production database,
> won't I be pulling in a very weak password that I used for development?  I 
> guess I can
> just change that.

Don’t do that.

> 2) Should I export all the content and structure from my development server 
> to my
> production server?  Or should I just create the database connection and then 
> run migrations and
> then create the data content on the production server?  Obviously, my 
> development server has
> minimal content.

Run the migrations and add the data.  There should be completely different data 
on the Production server as the dev server.

> 3) Should I just upload the other packages that I installed with pip on my 
> development server or
> should I instead run pip install on the production server to get all the 
> packages needed on the
> production server?  

Pip, pip, forever pip

> 4) Is it a best practice ( continuing from #3) to create a requirement file 
> and use that to install
> with pip all the packages, as opposed to uploading the packages from 
> development to production?  
> Note: I am developing on Ubuntu but deploying to Centos.  

Yes.  That way you can make changes to your install and just do `pip install -U 
-r requirements.txt` when there’s a bug fix to one of your things.

> 5) I suppose, even if I had a Centos development environment, I would still 
> want to install the required
> packages on the production server instead of just uploading everything.

Pip doesn’t use your distro.  It downloads from https://pypi.python.org/pypi

> Regarding #5, I am liking Python better than what I have used for some time, 
> PHP based application
> development.  However, for the longest time, things were much simpler with 
> php in that most php code is
> just text and so there isn't the notion of "installing" a package.  One could 
> expect things to work fine
> if one just uploaded the site from development to production (perhaps certain 
> new OO features are changing
> this situation for php sites, e.g. the use of autoloaders but that's another 
> topic).

First of all, that’s not quite true.  For many PHP features you have to install 
a package from your Linux distro.  Or figure out how to compile PHP yourself.  
Of course, many people just install all of the things, so that even if you 
don’t use a feature, it’s still a part of your monolithic PHP install.  This 
has been the case for over a decade.

> 6) Is there anything else, in addition to the top level assets (with js/css) 
> that I would want apache to serve directly
> versus going through mod_wsgi?  It seems like I read something to this effect 
> relating to parts of the admin, 
> that need to be served directly by apache.  I could be wrong.  

Anything that doesn’t change.  That includes images too.  The admin has it’s 
own CSS, JS, etc. that should be served by Apache.

> Thanks in advance for any help,
> Bruce  
> 
> P.S. If anyone wants to develop a course on udemy.com on a python framework, 
> please don't develop with
> sqlite3 since we won't use that in production and please discuss deployment 
> on a server besides 
> something like pythonanywhere.com.  The issues of setting things up on one's 
> own vps server are not 
> trivial at all.  (smile).
> 
> -- 
> 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 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com 
> <mailto:django-users@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users 
> <https://groups.google.com/group/django-users>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/50b71c19-10a1-4610-8050-191bde7facda%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/50b71c19-10a1-4610-8050-191bde7facda%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

Peter of the Norse
rahmc...@radio1190.org



-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2F54BB37-D020-4B91-9622-5F1A9566E615%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Passing hidden foreign key to form as initial value

2016-06-06 Thread Peter of the Norse
Because CharField is designed for text data.  So the form field turns the 
course into a string and tries to save a string to the model.  That doesn’t 
work.

The only built-in field designed to work with foreign keys is ModelChoiceField. 
 You could update it so that it doesn’t run a queryset and uses HiddenInput.

The other option is to remove course from the ModelForm and instead use 
course_id with IntergerField.  This would be the fastest and not hit the 
database as often.  I recommend doing this.  Or, if this uses an existing 
object, not have anything there.  Things left out of the ModelForm don’t get 
updated when you save the form. 

> On May 6, 2016, at 9:22 AM, Michel Z. Santello  wrote:
> 
> Can somebody explain why did occurs with widget=forms.HiddenInput ?
> 
> Thank's.
> 
> 
> 
> 
> Em quarta-feira, 31 de março de 2010 10:20:48 UTC-3, Phoebe Bright escreveu:
> Displayed fields resolve as expected, hidden fields cause errors.
> This works:
> 
> in the model
> CourseBook has a foreign key to Course
> 
> In the view:
> 
> course = Course.objects.get(pk=whatever)
> form = CouseBook(initial = {'course': course})
> 
> 
> in the Form:
> 
> class CourseBook(ModelForm):
> class Meta:
> model = CourseBooking
> 
> 
> The web page now displays a picklist of courses with the initial value
> highlighted.  I can now do a form.save() no problem.
> 
> However, if I make the course a hidden field, which is what I want.
> 
> class CourseBook(ModelForm):
> course = forms.CharField(widget=forms.HiddenInput())
> 
> class Meta:
> model = CourseBooking
> 
> then when I come to save() I get a ValueError, unable to assign "My
> course"  etc. as it tries to put the name of the course into the
> foreign key instead of a course instance.
> 
> I can work around this putting a save method on the form, but it seems
> to me django should resolve this for 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/3628bd01-59b2-4291-94f5-072d6de9f7c7%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Peter of the Norse
rahmc...@radio1190.org



-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20DEC617-798B-4178-9640-B96D254785AC%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: manipulate n insert field values

2016-06-04 Thread Peter of the Norse
I found this: https://github.com/trevorprater/pymorton

The problem is I’ve only done one search for Z curve, and I found three 
different ways to do it for lat/long.  Since there’s no standard 
implementation, there’s very little point to it.  If you are doing it to make 
it easier to search, then you can just create an index on (lat, long).

> On May 4, 2016, at 2:07 AM, Shameema Mohsin  wrote:
> 
> 
> Z value calculation
> 
> step1: converting lat and long to int
> 
> latitude int = (latitude + 90) × 10^6
> longitude int = (latitude + 180) × 10^6
> 
> note 10^6 = 100 
> 
> We compute the Morton value for a spatial point P (x, y)
> by interleaving the bits of x and y. For example, when x =
> 3(011 ) and y = 4(100), the Morton value for P is
> 100101 = 37 
> 
> step2: convert int (base 10) to binary digits (base 2)
> ..?
> step3: interleave both values bits and compute z value
> take first bit from y cordinate  (longitude) : 1
> take first bit from x cordinate  (lat) : 0
> take 2nd bit from y cordinate  (longitude) :0
> take 2nd bit from x cordinate  (lat) : 1
> #take 3rd bit from y cordinate  (longitude) : 0
> #take 3rd bit from x cordinate  (lat) : 1
> 
> therefore z binary value is 100101 
> and z value is 37
> 
> #this is the technique used to convert spatial 2D indexing to 1D to improve 
> efficiency.
> 
> I do not know the python syntax. Kindly help.
> 

Peter of the Norse
rahmc...@radio1190.org



-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/A32028E6-1085-4B4C-BF1B-6D5C4FC79BD4%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Django Multiple User Profiles Best Practices

2016-05-02 Thread Peter of the Norse
> On Apr 6, 2016, at 9:41 PM, Sudhanshu Shekhar  wrote:
> 
> Hi,
> 
> I am creating a tutor-student forum using Django. For which I need to have 
> two different user profiles, one for students and one for teachers. However, 
> I am unsure about the best way to do this. I am currently following the below 
> approach:
> 
> class UserProfile:
>  user = models.OneToOneField(User, reverse_name="profile")
>  #other common Attributes
>  class Meta(object):
>abstract = true
> 
> class TutorProfile():
>  #tutor fields
>  class Meta(object):
>abstract = true
> 
> class StudentProfile():
>   #student fields
>   class Meta(object):
>abstract = true
> 
> class Profile(TutorProfile, StudentProfile, UserProfile):
>   pass
> 
> 
> The idea is taken from the Django best practices book. However, I am curious 
> if there is any other way with lesser space usage. Any thoughts?
> 
> PS: I also asked the same question on stackoverflow : 
> http://stackoverflow.com/questions/36404889/django-multiple-user-profiles-with-class-based-views-best-practices
>  but didn't get any responses.


First of all, I don’t like multiple inheritance.  You are in control of all of 
the parent classes, so it might not blow up in your face, but there still night 
be problems down the line.  Second, I think this might be the same as just 
creating a single class with all of the fields, so there’s no reason to create 
three abstract classes for it to inherit from.

How old is the Django best practices book you are using?  Because starting with 
1.5, you should be using a custom User model 
<https://docs.djangoproject.com/en/1.9/topics/auth/customizing/#auth-custom-user>
 instead of a constant profile.

What I would do, and I’d love to hear some debate about it, is put most (or 
all, depending on requirements) of the fields from the UserProfile in the new 
custom user model, and have two not-abstract profiles with one-to-one fields to 
the user.  If the things in UserProfile don’t make sense for all users, then 
make three profiles which all point to the custom user model.

Peter of the Norse
rahmc...@radio1190.org



-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/D4629C3B-5B67-439B-B6B7-0EA2CC7CDFF5%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Q() chaining with & returns empty set

2016-04-21 Thread Peter of the Norse
They talk about this in the documentation.   
https://docs.djangoproject.com/en/1.8/topics/db/queries/#spanning-multi-valued-relationships
  Anything in a single filter() involves the same object.  For example, if you 
wanted to find all baskets containing a three pound banana, you would do 
Basket.objects.filter(fruit__weight=3.0, fruit__ofkind__name=‘banana’).  If you 
split them up into different filter()s, it would find baskets that have a three 
pound fruit of any type and a banana of any weight.

I think this is fairly new.  I’ve written code like 
Basket.objects.filter(fruit__in=Fruit.objects.filter(weight=3, 
ofkind__name=‘banana’)), but that uses a sub-select, and there are some 
databases *cough*MSSQL*cough* that choke on sub-selects.

> On Mar 30, 2016, at 8:14 PM, Bai Shun  wrote:
> 
> I've got a problem in using Q()
> 
> http://stackoverflow.com/questions/36299975/query-q-is-not-working-as-set-contain-for-related-field-in-django
>  
> <http://stackoverflow.com/questions/36299975/query-q-is-not-working-as-set-contain-for-related-field-in-django>
> 
> Let's say we have baskets of fruits. How to filter out those baskets that 
> contains all fruits in a given basket?
> 
> In this document 
> https://docs.djangoproject.com/en/dev/ref/models/querysets/#in 
> <https://docs.djangoproject.com/en/dev/ref/models/querysets/#in> 'in' method 
> seems will return any basket which contains any of the given fruit. Is there 
> any "set_contains" method to be used for filtering ? Such as 
> Basket.objects.filter(fruit_set_containsAll=fruitSet) ?
> 
> Edit: I found that Q() is not working as expected. I'll post the test here:
> 
> class Basket(models.Model):
> weight = models.FloatField(default=1)
> class Fruitname(models.Model):
> name = models.CharField(max_length=32)
> class Fruit(models.Model):
> ofkind = models.ForeignKey(Fruitname, on_delete=models.CASCADE)  
> inbasket = models.ForeignKey(Basket, on_delete=models.CASCADE)  
> weight = models.FloatField(default=1)
> the database is set as 'apple' only in 1 basket, 'pear' in 2 baskets, and 
> 'banana' in 3 basket:
> 
> print Basket.objects.all()
> print Fruitname.objects.all()
> [ 1. id - 53 apple(28), weight 1.00
> 2. id - 54 apple(28), weight 2.00
> 3. id - 55 apple(28), weight 3.00
> 4. id - 62 banana(30), weight 10.00
> >,  1. id - 56 pear(29), weight 4.00
> 2. id - 57 banana(30), weight 5.00
> >,  1. id - 58 pear(29), weight 6.00
> 2. id - 59 banana(30), weight 7.00
> 3. id - 60 pear(29), weight 8.00
> 4. id - 61 pear(29), weight 9.00
> >]
> [, , ]
> If I try to query with 'apple' and 'banana', it gives empty set !!
> 
> print 
> Basket.objects.filter(Q(fruit__ofkind__name__in=['apple'])&Q(fruit__ofkind__name__in=['banana'])).distinct()
> []
> similarly,
> 
> print 
> Basket.objects.filter(Q(fruit__ofkind__name__in=['banana'])&Q(fruit__ofkind__name__in=['pear'])).distinct()
> []
> Here's how I use 'in' to filter, it is not what I need which is supposed to 
> be an empty set.
> 
> print 
> Basket.objects.filter(Q(fruit__ofkind__name__in=['apple','pear'])).distinct()
> [ 1. id - 53 apple(28), weight 1.00
> 2. id - 54 apple(28), weight 2.00
> 3. id - 55 apple(28), weight 3.00
> 4. id - 62 banana(30), weight 10.00
> >,  1. id - 56 pear(29), weight 4.00
> 2. id - 57 banana(30), weight 5.00
> >,  1. id - 58 pear(29), weight 6.00
> 2. id - 59 banana(30), weight 7.00
> 3. id - 60 pear(29), weight 8.00
> 4. id - 61 pear(29), weight 9.00
> >]
> The only way that is working properly is chaining with filter:
> 
> Basket.objects.filter(fruit__ofkind__name__in=['apple']).filter(fruit__ofkind__name__in=['banana']).distinct()
> [ 1. id - 53 apple(28), weight 1.00
> 2. id - 54 apple(28), weight 2.00
> 3. id - 55 apple(28), weight 3.00
> 4. id - 62 banana(30), weight 10.00
> >]
> These code is tested with Django 1.9.4 Any explaining? I would undo the 
> accepted answer for the moment.
> 
> 
> 
> -- 
> 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 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com 
> <mailto:django-users@googlegroups.com>.
> Visit this group at https://groups.google.com

Re: Django tutorial part 3 - question_id vs question.id

2016-04-16 Thread Peter of the Norse
On Mar 26, 2016, at 8:04 AM, jorrit...@gmail.com wrote:
> 
> I believe Django lets you access the pk field of a table (which is created 
> automatically unless you define it explicitly on your model) in multiple 
> ways: self.pk, self.id, and self._id. Someone correct me if I’m 
> wrong.

You can’t use _id.  The closest is the foreign key ID.

Peter of the Norse
rahmc...@radio1190.org



-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/C006445C-23E3-41AC-842E-7EDF52143044%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: variable inside @media screen

2016-04-09 Thread Peter of the Norse
You also need a max-width or this will always be true.

> On Mar 11, 2016, at 2:21 AM, Rose  wrote:
> 
> @media screen and (min-width:767px){
> 

Peter of the Norse
rahmc...@radio1190.org



-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/37D9E424-CF35-4EFF-89CE-BF653856F704%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Problem uploading image Django 1.9 Python 3.5

2016-03-29 Thread Peter of the Norse
>From 
>https://docs.djangoproject.com/en/1.9/ref/models/fields/#django.db.models.fields.files.FieldFile.save,
> the content should be an instance of django.core.files.File.  So you code 
>should look like:

from dango.core.files import File
f = open(“c:\\NowHiring.jpg”, “rb”)
myfile = File(f)
imaged.full_photo.save(“NowHiring.jpg”, myfile)


> On Mar 2, 2016, at 1:31 AM, Povilas Kudriavcevas  wrote:
> 
> My problem is that when I try to save image to my model using Django shell I 
> get this error that I can't find solution anywere.
> 
> models.py
> 
> class AdImage(models.Model):
>ad = models.ForeignKey(Ad)
>full_photo = models.ImageField(upload_to='uploads/', blank=True)
> 
> I import models create AdImage instance add 'ad' and try to
> 
> imagead.full_photo.save("NowHiring.jpg",open("C:\\NowHiring.jpg", "rb"))
> 
> but i get an error
> 
> Traceback (most recent call last):
>   File "", line 1, in 
>   File 
> "C:\Users\hp\Envs\platform\lib\site-packages\django\db\models\fields\file
> s.py", line 106, in save
> self._size = content.size
> AttributeError: '_io.BufferedReader' object has no attribute 'size'
> 
> Using: Python 3.5, Django 1.9
> 
> What could I do ?
> 
> -- 
> 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 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com 
> <mailto:django-users@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users 
> <https://groups.google.com/group/django-users>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/d89d4906-0494-4d01-bd6a-428f29466f4d%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/d89d4906-0494-4d01-bd6a-428f29466f4d%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

Peter of the Norse
rahmc...@radio1190.org



-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/737C0E9D-88C9-4B19-8B89-63399F98A531%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: help with ManyToMany

2016-01-31 Thread Peter of the Norse
I hope you forgive me skipping all of that getattr nonsense.

others = Studio.objects.filter(studio_group__in = 
choice.studio_group_set.all()).exclude(pk=choice.pk)

> On Jan 28, 2016, at 2:16 AM, dave.l  wrote:
> 
> Hi,
> 
> I am happy with my models, and I'm fine inserting data, what I would like 
> help with is retrieval.
> 
> given a single instance of a Studio() I can get studio.studiogroup_set.all() 
> which I can then iterate to find the individual studios and build my 
> resulting list ensuring no duplicates and not 'studio' itself. All this is 
> working in Python:
> 
> choice = self.get_object()
> others = []
> for set in getattr(choice, "%s_set" % choice.groupname.lower()).all():
> for other in getattr(set, choice.view_name()).exclude(pk=choice.pk):
> if other not in others:
> others.append(other)
> for other in others:
> print other
> 
> but this doesn't seem very elegant and I'm wondering if there's a more 
> 'django' way of doing this.
> 
> On Wednesday, January 27, 2016 at 8:36:26 PM UTC, Xristos Xristoou wrote:
> your code is correct,where are the problem ?in the admin first add Studio and 
> sfter this select on the field studio from class studiogroup one or more 
> entries from the class studio so simple,
> 
> christos
> 
> Τη Τετάρτη, 27 Ιανουαρίου 2016 - 5:50:21 μ.μ. UTC+2, ο χρήστης dave.l έγραψε:
> Hi,
> 
> I have recently returned to a Django project after a few years and I'm a 
> little rusty on ManyToMany fields.
> 
> Here's my very simple models:
> 
> 
> class Studio(models.Model):
> name = models.CharField(max_length=255, unique=True)
> 
> class StudioGroup(models.Model):
> description = models.CharField(max_length=255, unique=True)
> studio = models.ManyToManyField(Studio)
> 
> 
> So a bunch of Studio(), which can be in multiple StudioGroups()
> 
> Given a single instance of a Studio(), I would like a single list of all 
> other studios in all other groups.
> 
> so if Group1 is A,B,C and Group2 is A,D,E
> 
> I would like to return B,C,D,E for A.
> 
> My current solution is entirely in Python (which works), but I'd like a more 
> Django-esque solultion of possible!
> 
> 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 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com 
> <mailto:django-users@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users 
> <https://groups.google.com/group/django-users>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/7512817d-d348-48b2-abf1-f3f584650cce%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/7512817d-d348-48b2-abf1-f3f584650cce%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

Peter of the Norse
rahmc...@radio1190.org



-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/10FA1403-DF5F-4DED-A2E9-C220D0C65653%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Reverse Foriegnkey filtering

2016-01-30 Thread Peter of the Norse
> On Jan 27, 2016, at 5:15 AM, Michal Petrucha  
> wrote:
> 
> On Wed, Jan 27, 2016 at 11:58:23AM +, Jonty Needham wrote:
>> I've found a need to do this and I'm struggling. Some info seems to
>> indicate that django doesn't support this. How is it meant to be done?
>> 
>> Basically to be clear, I need to filter one queryset on a reverse
>> foriegnkey relation to another set of objects defined by a particualr
>> filter.
>> 
>> model1(Models.model):
>>stuff = charfield
>> 
>> model2(Models.model):
>>cow = Foreignkey(model1)
>>country = charfield
>> 
>> 
>> Problem: filter set of model1's by a particular country that's related to
>> model1 through model2
> 
> If I read the problem correctly, the following should solve it::
> 
>model1.objects.filter(model2__country=my_country)
> 
> Cheers,
> 
> Michal

You also might need to follow up with .distinct() 
https://docs.djangoproject.com/en/1.8/ref/models/querysets/#django.db.models.query.QuerySet.distinct

Peter of the Norse
rahmc...@radio1190.org



-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/C8D0965D-3FEB-44CB-95ED-B913C1497244%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: self.publish.strftime('%m')

2016-01-30 Thread Peter of the Norse
You could use self.public.strftime(‘%Y’) without any problems here.  If fact, 
it might be a bit safer if the year is ever less then four digits.  Since month 
and day are exactly two digits in the URL, reverse has to make sure they match 
exactly.  That means making sure there is a leading zero.  With the year, you 
don’t have to worry about that, so it gets skipped.

> On Jan 26, 2016, at 6:30 AM, 林攀 <18610710...@163.com> wrote:
> 
> return reverse('blog:post_detail', args=[self.publish.year,
>  self.publish.strftime('%m'),
>  self.publish.strftime('%d'),
>  self.slug])
> url(r'^(?P\d{4})/(?P\d{2})/(?P\d{2})/(?P[-\w]+)/$',
> views.post_detail, name='post_detail'),
> 
> i feel confused why publish.year(type int) don't use strftime method .
> 

Peter of the Norse
rahmc...@radio1190.org



-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9C959670-19AE-48A3-97E7-A8C99E4A8A6B%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: I'm missing something with Models and database migrations

2015-12-27 Thread Peter of the Norse
 
> 
> However, when I push the code to Openshift, even though the migration runs 
> against the database, the invoice_id and line_item_id columns do not appear 
> on the database table. 
> 
> I have no idea what I'm doing wrong. Thank you for any help.
> 
> --Michael
> 
> -- 
> 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 https://groups.google.com/group/django-users 
> <https://groups.google.com/group/django-users>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/9953458c-908d-4376-89f9-eb68e37d527a%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/9953458c-908d-4376-89f9-eb68e37d527a%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <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 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com 
> <mailto:django-users@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users 
> <https://groups.google.com/group/django-users>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/848c0bba-993a-4599-9829-3c8081af32ec%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/848c0bba-993a-4599-9829-3c8081af32ec%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

Peter of the Norse
rahmc...@radio1190.org



-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/D8D9B2CA-AA81-46B7-B4CF-C206E6741CB9%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: django-admin.py startproject mysite

2015-11-10 Thread Peter of the Norse
0.0.0.0 is not an actual IP address.  You can’t put it in your browser.  
Instead, you need to find your computer’s IP address and use that.  How you 
find it depends on your OS, but once you do, then you can visit 
http://192.168.0.5:8000/ (for example). 

> On Nov 4, 2015, at 5:50 PM, Muhammad Asamov  wrote:
> 
> HI 
> I was wodering whether someone can hepl me with startproject 
> 
> The thing is when I am running startproject from the server ip 127.0.0.1:8000 
> which was created automaticly i can see the result but if i give different 
> address:
> 0.0.0.0:8000 I can see nothing it is not showing anything 
> 
> Actually I was giving this address cause wanted to see mysite from another 
> computer 
> and don't know why it is not working
> 

Peter of the Norse
rahmc...@radio1190.org



-- 
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/4D4E4799-4A8F-48A8-A0EF-535BFFB8DFA0%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Models.clean() how to raise ValidationError WITH error_code and show field_based errors in the Form-Template?

2015-08-29 Thread Peter of the Norse
You are raising a dict style ValidationError.  To get the actual fields you 
need to use the_exception.error_dict[’note’].error_list[0].code.  

> On Jul 30, 2015, at 4:10 AM, ThomasTheDjangoFan 
>  wrote:
> 
> class TestMyNotebookModelTest(unittest):
> def test_clean(self):
> # I'd love to be able to do a test like this one
> # and valide the error code!
> 
> # Lets get an error-message
> with self.assertRaises(ValidationError) as test:
> model = MyNotebookModel()
> model.note = 'Now this is a valid one. P.S. I love django!'
> model.name = 'Britney is gonna fail - Hit me Baby One More Time!'
> model.clean()
> model.save()
> # validate that the error messages has the right code
> the_exception = test.exception
> self.assertEqual(the_exception.error_code, 2)

Peter of the Norse
rahmc...@radio1190.org



-- 
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/979B813D-C9D4-4933-9A8E-1921A73DD991%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Django Logical Deletes on Models

2015-08-08 Thread Peter of the Norse
Steal code from the current Model.delete method.  It uses 
django.db.models.deletion.Collector to find the associated objects.  I would 
extend that to do what you want.

> On Aug 4, 2015, at 7:38 AM, psychok7  wrote:
> 
> So i decided to fork pinax-models because i need the capability of soft 
> deleting objects and their related (setting a flag but not really deleting 
> them). This is a project that seems to be unmaintained , so i diged into the 
> code and i am trying to make some improvements.
> 
> 
> 
> It basically fetched the objects, looks for its related and then saves the 
> date_removed to fake the deletion.
> 
> It still has some issues and one of them which i am trying to solve is that 
> it always "cascades" the deletes of the related but it should only do it if 
> the related field is not nullable. if its nullable then it should not delete 
> the related field.
> 
> 
> 
> I have 2 question regarding this matter ( i  am using Django 1.7):
> 
> 1- How can i improve this code below to support that feature? I know it has 
> something to do with _meta, thought about using 
> `obj._meta.get_fields_with_model` but i am afraid it does not do 
> `options.concrete_fields + options.many_to_many + options.virtual_fields`. i 
> was thinking about getting  all the existing fields in a model an then 
> evaluate if its a foreign key to a certain model class and then check if 
> `obj._meta.get_field('something').null`. Is this the right approach??
> 
> 
> 
> 2 - The original author is using self._meta.get_all_related_objects() but in 
> the _metadocumentation i saw other functions like for example 
> get_all_related_many_to_many_objectsso do i need to add that validation to 
> the code as well or self._meta.get_all_related_objects() is enough ??
> 
> 
> 
> I am trying to improve this and push it to my pinax-models fork so any help 
> would be appreciated.
> 
> code:
> 
> 
> 
> class CustomLogicalDeleteModel(LogicalDeleteModel):
> 
> def delete(self):
> # Fetch related models
> related_objs = [
> relation.get_accessor_name()
> for relation in self._meta.get_all_related_objects()
> ]
> 
> for objs_model in related_objs:
> 
> if hasattr(self, objs_model):
> local_objs_model = getattr(self, objs_model)
> if hasattr(local_objs_model, 'all'):
> # Retrieve all related objects
> objs = local_objs_model.all()
> 
> for obj in objs:
> # Checking if inherits from logicaldelete
> if not issubclass(obj.__class__, LogicalDeleteModel):
> break
> obj.delete()
> else:
> obj = local_objs_model
> 
> if not issubclass(obj.__class__, LogicalDeleteModel):
> break
> obj.delete()
> 
> # Soft delete the object
> self.date_removed = datetime.datetime.now()
> self.save()
> 
> class Meta:
> abstract = True
> 
> -- 
> 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 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com 
> <mailto:django-users@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/52a0b2b6-2fb6-44ad-9ab9-fd05613c1622%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/52a0b2b6-2fb6-44ad-9ab9-fd05613c1622%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

Peter of the Norse
rahmc...@radio1190.org



-- 
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/818DF3E6-1A1A-40B9-AB87-2BE50EC6587C%40radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Django formset hidden id field

2015-07-03 Thread Peter of the Norse

> On Jul 2, 2015, at 7:46 PM, Carl Meyer  wrote:
> 
>> So what?  It’s quite likely that whoever is editing this row of the
>> database, also has permissions to edit the other rows as well.  There’s
>> no reason for them to go through the hassle of manually editing a hidden
>> field when they can go to a different page and edit it there.
> 
> That's a bad answer. It's common in many systems for a user to have
> access to edit some records in a table but not others (this is often
> known as "object-level permissions"). If it was really possible to edit
> any row in the table by just manually editing the PK hidden field, that
> would be a serious security flaw in formsets.
> 
> But it's not. Whatever queryset you pass to the model formset limits the
> available rows for editing. The end user can edit the PK to refer to any
> item in that queryset, but not any item in the table.
> 
>> In general, primary keys are not security flaws.  While it’s a good idea
>> to hide them from front-end pages, that’s mostly because they make URLs
>> hard to read.  I have heard that you don’t want to use them publicly,
>> because your competitors can use them to gauge your success, but that’s
>> the kind of “Nice Problem to Have” that can wait until you’re bigger.
> 
> Exposing primary keys themselves (e.g. in URLs) is not necessarily a
> security flaw. Exposing a primary key in a hidden field that can be
> edited to change a form to edit any row in a table often would be a
> serious security flaw.

You can’t have it both ways. Either exposing the PK is a security flaw or it 
isn’t. It’s just as easy for nefarious n’er-do-wells to edit the form’s URL as 
a hidden field. In either case, if you are using object-level permissions, more 
checks (not made automatic in Django) are necessary. Having the ID passed as a 
parameter doesn’t necessitate, hinder, or alleviate running these checks.

If you can come up with a method that associates form data with a database row 
that doesn’t involve the PK, I would love to know. Keep in mind that most 
tables only have the one unique identifier.

Peter of the Norse
rahmc...@radio1190.org



-- 
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/F9FAB5F9-F4EA-45C8-834A-FB39B26F4B63%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Django formset hidden id field

2015-06-28 Thread Peter of the Norse
On May 27, 2015, at 7:47 AM, Cheng Guo  wrote:
> 
> Hello,
> 
> I have a formset and when I render it, Django would include this line in the 
> HTML:
> 
> 
> I am curious what is the purpose of having an id field here. 
> 
> I mean in what situation would you use it. I did look through Django's 
> documentation on formset 
> <https://docs.djangoproject.com/en/1.8/topics/forms/formsets/#can-delete>but 
> cannot find much documentation on this.
> 
> One answer I got is that this id field is the value of the primary key of the 
> model bound to this form. It is there so that when the formset updates, 
> people can use it to retrieve the corresponding record from the database.
> 
> Is the above explaination correct?
> 
> If this explaination is correct, then my next question is, wouldn't it be 
> dangerous to expose the primary key like that? I can make a post call to your 
> server with a modified pk which can mess up your database.

So what?  It’s quite likely that whoever is editing this row of the database, 
also has permissions to edit the other rows as well.  There’s no reason for 
them to go through the hassle of manually editing a hidden field when they can 
go to a different page and edit it there.

In general, primary keys are not security flaws.  While it’s a good idea to 
hide them from front-end pages, that’s mostly because they make URLs hard to 
read.  I have heard that you don’t want to use them publicly, because your 
competitors can use them to gauge your success, but that’s the kind of “Nice 
Problem to Have” that can wait until you’re bigger.

> Thank you!

Peter of the Norse
rahmc...@radio1190.org



-- 
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/46F4D6D3-A414-4810-A460-1DBDBE20784B%40radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: How to DRY, define a set of model-fields and reuse them as multiple instances

2015-06-14 Thread Peter of the Norse

> On Jun 10, 2015, at 10:33 AM, ThomasTheDjangoFan 
>  wrote:
> 
> Hi Bruno,
> 
> Abstract Base Models come close but they don't allow me to combine multiple 
> instances of the BaseModel in the DataHolderModel.
> 
> My goal is to store them all in one table without having to manually add all 
> the fields.
> 
> Any suggestions?


There’s a django-compound-field package that seems to be what you want, but it 
hasn’t been updated in five years, so it won’t work with any recent version.  
Still, it might be a place to start from.

Peter of the Norse
rahmc...@radio1190.org



-- 
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/6595F9D2-B97A-4E86-9C2B-E8EE1B302237%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Scaling/Parallel patterns for a View executing complex database transaction

2015-06-14 Thread Peter of the Norse
On May 14, 2015, at 10:30 PM, Me Sulphur  wrote:
> 
> * It is a large key-value pair table (approaching ~ 1 bn rows) with an MD5 
> key and JSON  for value. The look ups depend on the business logic but are 
> necessary. Nevertheless, there are no more than 10-12 queries executed by 
> combining key look ups using WHERE IN queries and pg is surprisingly good 
> with IN queries.


If this is the case, then I strongly recommend switching to a NoSQL DB.  You 
aren’t using any of the Django ORM functionality, so there’s no need to switch 
to django-nonrel.  Almost all of them are faster at key/value returns than 
PostgreSQL.  

Peter of the Norse
rahmc...@radio1190.org



-- 
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/794491DD-ADB8-422A-AE03-0D4D8546E4E2%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Migrating from sqllite3 to postgres

2015-05-25 Thread Peter of the Norse

> On May 21, 2015, at 11:24 PM, jaspinder singh  
> wrote:
> 
> I have developed an app using sqllite. But my Heroku doesn't support sqllite 
> and the data keeps leaking every 24 hours. Can someone list the steps how to 
> change from sqllite3 to postgres
> 


>From sqlite:
sqlite> .output backup.sql
sqlite> .dump

>From the command line:
$ psql django_db -1f backup.sql

You may have to edit the .sql file to make it work. Good luck.

Peter of the Norse
rahmc...@radio1190.org



-- 
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/53FD5433-F4CA-4684-9BF5-E9FA4EA786C4%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Changing table name in response to a QuerySet

2015-03-22 Thread Peter of the Norse
I’m not sure I explained myself that well. Our system has two models, Product 
and ProductSearch. The Product tables come from third party sources, and can’t 
be edited from the front end. Users can setup their own ProductSearches, which 
are then used to construct the queryset. So our code actually looks more like:

model = Product.get_subtable(‘foo’)
logger.info(’start first run of get_queryset’)
qs = user_product_search.get_queryset(request, model)
logger.info(‘finished first run of get_queryset’) 

logger.info(’starting count() of qs for the first time’)
product_count = qs.count() 
logger.info(‘finish count() of qs’)
if product_count == 0:
model = Product.get_subtable(‘foo’)
logger.info(’start second run of get_queryset’)
qs = user_product_search.get_queryset(request, model)
logger.info(‘finished second run of get_queryset’)

In the worst case scenario, the actual count() runs in about 150-250ms, (we 
have some good indexes) the first get_queryset call takes ~800ms (there are DB 
look-ups) and the second can take 200ms (we cache the DB values).  This is 
200ms slower than the old way of “c = qs.filter(source=‘foo’).count(); if c>0: 
qs = qs.filter(source=‘foo’) else: qs = qs.filter(source=‘bar’)”. And about 
3000ms faster than building up the raw SQL that we used to do. (Actually, the 
problem comes because we use the queryset in a dozen different ways depending 
on other things that need to be looked up. Seriously, the ORM is faster than 
trying to roll our own.)

> On Mar 18, 2015, at 11:04 PM, James Schneider  wrote:
> 
> Wow, that's quite the queryset! 
> 
> If I understand your snippet right, it looks as though you always run an 
> initial large query against one of the tables, and if it doesn't find 
> anything, run the similar query against the other table. If the filters, etc. 
> are exactly the same, you could take the raw SQL from the first query and 
> perform a substitution for the new model name, and just run the raw SQL for 
> the second iteration, rather than depending on the ORM to (re)build the query 
> for you. That may not be an option if you are heavily depending on the ORM to 
> package up the results nicely for you. Given the complexity of your query, 
> raw SQL may buy you some serious performance gains if you are able to 
> optimize the query that the ORM would normally generate.
> 
> This may be one of those cases where the limitations of the ORM are being 
> reached, however, I'll defer any further comment to others on the list.
> 
> -James
> 
> 
> On Wed, Mar 18, 2015 at 9:35 PM, Peter of the Norse  <mailto:rahmc...@radio1190.org>> wrote:
> I’m already doing all of that. The problem is we often have logic that goes 
> like:
> 
> model = Product.get_subtable(‘foo’)
> queryset = model.objects.
> filter(…).
> select_related(…).
> exclude(…).
> extra(…)
> … and so on and so on. Seriously, the method that constructs the queryset 
> is some 1500 lines long and can quite a bit to run
> if queryset.count() == 0:
> model = Product.get_subtable(‘bar’)
> queryset = model.objects.
> filter(…).
> select_related(…).
> exclude(…).
> extra(…)
> … the same expensive method again.
> 
> A lot of our performance gains have come from caching the queryset creation 
> function, but even with all of that the method can still take 200ms to run. 
> (Seriously, there can be over 40 filters, some of which are complex Q() and 
> F() objects.) The problem is the second queryset produces almost the exact 
> same SQL, but with one table having a different name. Back when we were 
> creating the raw SQL, it was a simple string replace to switch tables. I was 
> hoping that someone had some kind of “switch table” command on the queryset 
> or something similar.
> 
>> On Mar 17, 2015, at 3:08 AM, James Schneider > <mailto:jrschneide...@gmail.com>> wrote:
>> 
>> That sounds more like an exact use case for model inheritance. You would 
>> define a single model that matches the columns in both tables. You can 
>> define that model as abstract, then have the two real models (one for each 
>> table) inherit from that abstract model. In the definition for the child 
>> models, you would specify the DB table names to match your two tables in the 
>> existing schema.
>> 
>> https://docs.djangoproject.com/en/1.7/ref/models/options/#db-table 
>> <https://docs.djangoproject.com/en/1.7/ref/models/options/#db-table>
>> That way, you only maintain a single (abstract) model definition, even 
>> though multiple models use it (each with a separate DB table).
>> 
>> You may also need to mark the real models as unmanaged by the ORM if you're 
>> doing

Re: Different between Object-save and form-save

2015-03-18 Thread Peter of the Norse
s 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 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com 
> <mailto:django-users@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/CAMGzuy8aX8ehs4Qd2RgkueERA-OmDQg8gbE%3DVxJCB8heKw%2B03A%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/django-users/CAMGzuy8aX8ehs4Qd2RgkueERA-OmDQg8gbE%3DVxJCB8heKw%2B03A%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

Peter of the Norse
rahmc...@radio1190.org



-- 
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/80CDB44E-46B0-4860-A78F-31692716DB29%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Changing table name in response to a QuerySet

2015-03-18 Thread Peter of the Norse
I’m already doing all of that. The problem is we often have logic that goes 
like:

model = Product.get_subtable(‘foo’)
queryset = model.objects.
filter(…).
select_related(…).
exclude(…).
extra(…)
… and so on and so on. Seriously, the method that constructs the queryset 
is some 1500 lines long and can quite a bit to run
if queryset.count() == 0:
model = Product.get_subtable(‘bar’)
queryset = model.objects.
filter(…).
select_related(…).
exclude(…).
extra(…)
… the same expensive method again.

A lot of our performance gains have come from caching the queryset creation 
function, but even with all of that the method can still take 200ms to run. 
(Seriously, there can be over 40 filters, some of which are complex Q() and F() 
objects.) The problem is the second queryset produces almost the exact same 
SQL, but with one table having a different name. Back when we were creating the 
raw SQL, it was a simple string replace to switch tables. I was hoping that 
someone had some kind of “switch table” command on the queryset or something 
similar.

> On Mar 17, 2015, at 3:08 AM, James Schneider  wrote:
> 
> That sounds more like an exact use case for model inheritance. You would 
> define a single model that matches the columns in both tables. You can define 
> that model as abstract, then have the two real models (one for each table) 
> inherit from that abstract model. In the definition for the child models, you 
> would specify the DB table names to match your two tables in the existing 
> schema.
> 
> https://docs.djangoproject.com/en/1.7/ref/models/options/#db-table 
> <https://docs.djangoproject.com/en/1.7/ref/models/options/#db-table>
> That way, you only maintain a single (abstract) model definition, even though 
> multiple models use it (each with a separate DB table).
> 
> You may also need to mark the real models as unmanaged by the ORM if you're 
> doing funny things directly in the DB, and you will be managing the table 
> schema directly for those tables.
> 
> https://docs.djangoproject.com/en/1.7/ref/models/options/#managed 
> <https://docs.djangoproject.com/en/1.7/ref/models/options/#managed>
> I'm assuming you have already determined the logic deciding which model each 
> user uses. At that point, assuming that all other functionality remains the 
> same (calls/processing the data, regardless of table), the calls to those 
> models can be generalized by a simple utility function that returns a class 
> instance of the necessary model.
> 
> def get_right_model(user):
> # logic to pick ModelA or ModelB based on user
> return ModelA
> 
> Then later, maybe in a view:
> 
> selected_model = get_right_model(self.request.user)
> 
> all_data = selected_model.objects.all()
> 
> #all_data should now contain the results of the query against the right 
> model/table in the DB
> 
> Trying to flip between tables in the ORM by tweaking the innards probably is 
> going to lead to excessive complication.
> 
> -James
> 
> -- 
> 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 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com 
> <mailto:django-users@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/CA%2Be%2BciXKkQ2Lpq1F-KBpHkndLWxi_8dCVamXJ-G7Bji3QZWcmA%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/django-users/CA%2Be%2BciXKkQ2Lpq1F-KBpHkndLWxi_8dCVamXJ-G7Bji3QZWcmA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

Peter of the Norse
rahmc...@radio1190.org



-- 
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/0435A65C-4A7A-4DFA-A1C2-8951437FFB2B%40Radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Changing table name in response to a QuerySet

2015-03-16 Thread Peter of the Norse
We have two tables that — for legal reasons — are not allowed to be combined. 
The data is so similar that we are using PostgreSQL table inheritance 
<http://www.postgresql.org/docs/9.4/static/ddl-inherit.html>, but we can’t 
return the information in the same page. Originally, we only had one table with 
a column specifying which data set to use, but or lawyers put an end to that.

So we have two tables tables with the exact same columns: product_foo and 
product_bar. We also have two models that use model inheritance so that they 
have the exact same fields: ProductFoo and ProductBar. The decision to choose 
which table to use is handled based on user settings.

We would like to go back to just having the one Product model, and have its 
table name switch as necessary. Is there a way to do that?

Peter of the Norse
rahmc...@radio1190.org



-- 
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/0A706025-5A66-47E3-B524-222E1780ADA4%40radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: Webcomponents in Django

2014-12-18 Thread Peter of the Norse

On 11/19/2014 7:18 AM, Timothy W. Cook wrote:

then the designer-element.html is imported:
href="elements/designer-element/designer-element.html">


Here's your problem.  This is a relative link, so the current directory 
gets used as the base, and it tries to load 
http://127.0.0.1/designer/elements/designer-element/designer-element.html. 
That matches

url(r'^designer/', (DesignerView.as_view()), name='designer')

because there's not a $ at the end of the pattern.

And it loads the page again.  That page also has the same relative link, 
but this time in a different file, so it creates the new link as 
http://127.0.0.1/designer/elements/designer-element/elements/designer-element/designer-element.html 
and the process starts all over again.


This isn't a Django problem but an HTML problem.

--
Peter of the Norse

--
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/54932746.1090705%40radio1190.org.
For more options, visit https://groups.google.com/d/optout.


Re: How to urlquote backslash in reverse arguments

2014-01-15 Thread Peter of the Norse
Someone will have to correct me if I'm wrong, but it might be 
intentional. Some recent versions of Apache fail hard when confronted 
with an encoded slash. Some decode it before passing it to WSGI, while 
others don't. And then there are the versions that return 500 or 400 
errors. And then there are the other servers that try to emulate the 
behavior without consideration.


I just checked, and percent signs, question, and hash marks (%?#) aren't 
encoded either. So, yeah, that's a bug.


On 12/17/2013 3:15 AM, Vitaly wrote:

But why backslash is not? How to make it urlquoted to %2F in that case?

Python 2.7.6 (default, Nov 26 2013, 12:47:31)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.core.urlresolvers import reverse
>>> reverse('events-index', kwargs={'tag': 'PL/SQL'})
'/calendar/tags/PL/SQL/'
>>> reverse('events-index', kwargs={'tag': 'PLЄ/SQL'})
'/calendar/tags/PL%D0%84/SQL/'
>>> 



--
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/a55c505d-e7d2-4a85-aade-761913d544e9%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.


--
Peter of the Norse

--
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/52D6E297.5000501%40radio1190.org.
For more options, visit https://groups.google.com/groups/opt_out.


Re: export .csv file from database

2013-07-19 Thread Peter of the Norse
Two things: 
First, Ms Excel sucks. From that attached screenshot it's obvious that it 
thought it was a space separated file. When actually using MS Office, I 
recommend that you add `quoting=csv.QUOTE_ALL` to all csv writers. 

Second, the HttpResponse object is file-like. You don't need to jump through 
all the hoops. And MS Office is going to ignore your encoding anyway, so 
there's no point in trying to fix it.

On Jun 17, 2013, at 9:44 AM, roopasingh...@gmail.com wrote:

> views.py
> 
> @login_required
> def export_csv(request):
> user = request.user
> # heading columns
> headerrow = ['Filename', 'Description','Notes other','Reporter Name']
> allrows = []
> today = datetime.datetime.today() # default to show today
> reports = Report.objects.filter(user=user)
> reports = reports.filter(created_date_time__year=today.year)
> for report in reports:
> row = []
> row.append(report.report_number);
> row.append(report.report_description);
> row.append(report.notes_other);
> row.append(report.reporter_name);
> allrows.append(row)
> # setup CSV export
> response = HttpResponse(mimetype='text/csv')
> filename = "%s-%s.csv" % ('Daily-reports', 
> datetime.datetime.now().strftime('%Y-%m-%d'))
> response['Content-Disposition'] = 'attachment; filename=%s' % filename
> writer = UnicodeWriter(response, encoding='utf-8')
> writer.writerow(headerrow)
> for writerow in allrows:
> writer.writerow(writerow)
> return response
> 
> csv_unicode.py
> 
> import csv, codecs, cStringIO
> class UnicodeWriter:
>def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
> # Redirect output to a queue
> self.queue = cStringIO.StringIO()
> self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
> self.stream = f
> self.encoder = codecs.getincrementalencoder(encoding)()
> 
> def writerow(self, row):
> self.writer.writerow([unicode(s).encode("utf-8") for s in row])
> # Fetch UTF-8 output from the queue ...
> data = self.queue.getvalue()
> data = data.decode("utf-8")
> # ... and reencode it into the target encoding
> data = self.encoder.encode(data)
> # write to the target stream
> self.stream.write(data)
> # empty queue
> self.queue.truncate(0)
> 
> def writerows(self, rows):
> for row in rows:
> self.writerow(row)
> 
> The above code is exporting the database data into .csv file.
> 
> Problem i am facing is,the exported data like Filename,Description,Notes 
> Others,Reporter Name are exported in separate cell.Will show the output
>  i am getting and required output.
> 
> You can see my existing and required format. 
> 
> I had attached two format,file name existing_csv is the output file i ma 
> getting,required_csv is the .csv file i am expecting.
> 
> Need some ones help.

Peter of the Norse
rahmc...@radio1190.org



-- 
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 queryset 'in' operator fails on first call

2013-04-13 Thread Peter of the Norse

On Apr 10, 2013, at 7:44 AM, bradley griffiths wrote:

> Corss posted from stack overflow
> 
> When using the 'in' operator on a queryset, the first time the call is made 
> it fails.
> 
> from django.db import models
> 
> 
> class Category(models.Model):
> name = models.CharField(max_length=100)
> 
> 
> class Project(models.Model):
> categories = models.ManyToManyField(Category, related_name='projects')
> 
> 
> category_list = Category.objects.prefetch_related('projects')
> 
> 
> print category_list # [,  object>]
> print category_list[0] in category_list # False
> print category_list[0] in category_list # True
> If I remove 'prefetch_related' and use 'all' instead then the problem is 
> gone, however this uses many more DB calls.
> 
> How can I get the correct result first time using prefetch_related?
> 

You might try converting the QuerySet into a list first. QuerySets avoid 
actually caching data for as long as possible.

Peter of the Norse
rahmc...@radio1190.org



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




Re: How to get ten random records

2013-03-22 Thread Peter of the Norse
Don’t listen to him. .order_by('?') is the right thing. If you’re not sure, 
install django-debug-toolbar. You’ll see that you get "ORDER BY random()". 

Also, while .get() will throw an exception if the QuerySet is empty, nothing 
else will.

On Mar 18, 2013, at 10:46 PM, Mike Dewhirst wrote:

> On 19/03/2013 3:29pm, Christophe Pettus wrote:
>> 
>> On Mar 18, 2013, at 9:03 PM, Mike Dewhirst wrote:
>> 
>>> No really, I want a maximum of ten random records from the database
>>> (Django 1.4, Postgres 9.1).
>> 
>> This is a case where the raw SQL interface might be the right answer:
>> you can just tack an ORDER BY random() clause onto the query.
> 
> Thank you kind sir
> 
> Cheers
> 
> Mike
> 
>> 
>> -- -- Christophe Pettus x...@thebuild.com
>> 
> 

Peter of the Norse
rahmc...@radio1190.org



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




Re: Performance when retrieving data from related models

2013-03-18 Thread Peter of the Norse
More inline stuff. 

On Mar 18, 2013, at 4:14 AM, Taras D wrote:

> Hi Peter
> 
> On 18 March 2013 16:35, Peter of the Norse  wrote:
> You’re over thinking this by a large margin. getTendersForContractor should 
> return a QuerySet. That way you can add things like .select_related as 
> necessary in the view. 
> 
> Also, I’m a bit worried about the fact you have a function called 
> getTendersForContractor. It really should be Tender.objects.forContractor. Or 
> if the function is just a single filter call, it can be eliminated entirely.
> 
> To confirm, this would require a new Manager that implements the 
> 'forContractor' method?

Yes. 

>> * Prefetch_related selects related obects via the criteria: 'in (list of 
>> ids'), which arguably can be slower
> 
> What database are you using where this is true?
> 
> It was the result of a discussion with a colleague. Also slides 67 & 68 at 
> http://www.slideshare.net/OReillyOSCON/unbreaking-your-django-application 
> imply that large IN's may cause performance problems - 
> "68:  Large INs are a mess.  Very expensive for the database to parse.  Very 
> expensive for the database to execute.  If there are potentially more than 
> 10-15 items in the list, rework the IN as a JOIN against whatever the source 
> of the keys is." 

That sounds like a good candidate for a bug ticket. It’s not trivial though. 
The limit of IDs in the query set would depend on the database, the complexity 
of the query, and the data being pulled. I would have to think about this for a 
long time before I felt comfortable making any kind of suggestion.

>> * Seems brittle - if you change the data model, you have to change all of 
>> the queries in the data retrieval layer. Denomralising the data would reduce 
>> this, but we'd still have the problem of retrieving more data than the 
>> client may possibly want
> Yes, if you change code in one place, you might have to change it someplace 
> else to match it. Most of us just use the ORM as the data retrieval layer. 
> Again, I’m worried you’re over thinking this.
> 
> I hadn't really considered passing around a QuerySet in place of a list of 
> Tenders. One thing I'm finding is that the cost in retrieving related objects 
> is making me rethink the API presented to the client. For example, consider 
> the following API, which I think is quite reasonable:
> 
> class Tender:
>   def getTotalCost(self):
>   return self.project.getTotalCost()
> 
> class Project:
>   
>   def getTotalCost(self):
>   cost = 0
>   for contract in self.contract_set.all():
>   cost += constract.getTotalCost()
>   return cost
> 
> similarly implementations for Project & Contract
> 
> class Contract:
>   def getTotalCost(self):
>   cost = 0
>   for job in self.job_set.all():
>   cost += job.getTotalCost()
>   return cost

https://docs.djangoproject.com/en/dev/topics/db/aggregation/

> Having a Project know how much its total cost is, and presenting this to a 
> client, is in line with OO principles of abstraction and encapsulation. 
> Consider a page that outputs the total cost of each contract tendered for a 
> particular contractor. If we re-use the 'getTendersForContractor' function 
> (that returns a QuerySet), and then call 'getTotalCost' on each Project that 
> has a tender, then we still have a problem in that we'll get a multitude of 
> calls to the database. 
> 
> We might put the onus on the client to call:
> qs = getTendersForContractor(contractor)
> for tender in list(qs.prefetch_related('project', 'project__contract', 
> 'project__contract')):
> print tender, tender.getTotalCost()

If this is really what you are doing, then I strongly recommend 
https://docs.djangoproject.com/en/dev/topics/db/aggregation/. This case is a 
single SQL statement.

> Not only is this complicated, but this requires the client know how the 
> Tender is implemented (the prefetched would become uneccessary if we changed 
> the implementation to store the total cost on the actual Tender itself at the 
> cost of denormalised data). Note that you wouldn't have these problems if the 
> data existed in memory.
> 
> These points are making me rethink my data model and API design, and that the 
> OO paradigm doesn't always fit well with web apps. In particular the slides 
> at http://www.slideshare.net/OReillyOSCON/unbreaking-your-django-application:
> 
> 23: "Django doesn’t have a good primitive for returning an object graph in 
> one call. - multiple db trips required" Implies that object gr

Re: Performance when retrieving data from related models

2013-03-17 Thread Peter of the Norse
You’re over thinking this by a large margin. getTendersForContractor should 
return a QuerySet. That way you can add things like .select_related as 
necessary in the view. 

Also, I’m a bit worried about the fact you have a function called 
getTendersForContractor. It really should be Tender.objects.forContractor. Or 
if the function is just a single filter call, it can be eliminated entirely.

On Mar 15, 2013, at 9:04 PM, Taras_96 wrote:

> qs = Tender.objects.sql_related(/*names of keyed relationships 
> here*/).prefetch_related('project', 'project__job_set') (the actual example 
> has many more relations in the prefetch_related). This fixes the problem of 
> hitting the database in loops such as the above, and the complexity can be 
> hidden in a data retrieval layer that the client calls into.
> 
> returnedTenders = getTendersForContractor(contractor) # << the actual query 
> with prefetches etc is done in this function
> 
> However, there are a few drawbacks to this:
[SNIP]
> * Each prefetch_related hits the database once - a lot better than 3k hits, 
> but not as minimal as a sql join which joins all of the tables
Actually, no. If you were to try and do the prefetch_related as a single SQL 
join, you would return an insane number of rows. A single prefetch_related 
wouldn't be a problem, but if you were to try and do a select with more than 
one many field, they would multiply. If you have an example of a join statement 
that doesn’t do that, we’d love to see it.

> * Prefetch_related selects related obects via the criteria: 'in (list of 
> ids'), which arguably can be slower
What database are you using where this is true?

> * Seems brittle - if you change the data model, you have to change all of the 
> queries in the data retrieval layer. Denomralising the data would reduce 
> this, but we'd still have the problem of retrieving more data than the client 
> may possibly want
Yes, if you change code in one place, you might have to change it someplace 
else to match it. Most of us just use the ORM as the data retrieval layer. 
Again, I’m worried you’re over thinking this.


Peter of the Norse
rahmc...@radio1190.org



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




Re: IntegrityError after updating to custom user field: django_admin_log still has fk to auth_user

2013-03-02 Thread Peter of the Norse
This sound like a South kind of problem. Your tables were created with a 
foreign key from django_admin_log to auth_user, but you’re not longer using 
auth_user. You’ll have to drop the foreign key and recreate it to remove this 
error.

On Feb 27, 2013, at 4:17 PM, Ben Roberts wrote:

> This ring any bells? I updated my existing site to utilize my new Django 1.5 
> custom user field, and now I can't update anything in Admin because i get the 
> following error: (django_admin_log still has a fk to auth_user, apparently!) 
> Any way to resolve this?
> 
> 
> 
> Traceback (most recent call last):
> 
>   File 
> "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py",
>  line 115, in get_response
> response = callback(request, *callback_args, **callback_kwargs)
> 
>   File 
> "/app/.heroku/python/lib/python2.7/site-packages/newrelic-1.10.0.28/newrelic/api/object_wrapper.py",
>  line 220, in __call__
> self._nr_instance, args, kwargs)
> 
>   File 
> "/app/.heroku/python/lib/python2.7/site-packages/newrelic-1.10.0.28/newrelic/hooks/framework_django.py",
>  line 475, in wrapper
> return wrapped(*args, **kwargs)
> 
>   File 
> "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/admin/options.py",
>  line 372, in wrapper
> return self.admin_site.admin_view(view)(*args, **kwargs)
> 
>   File 
> "/app/.heroku/python/lib/python2.7/site-packages/django/utils/decorators.py", 
> line 91, in _wrapped_view
> response = view_func(request, *args, **kwargs)
> 
>   File 
> "/app/.heroku/python/lib/python2.7/site-packages/django/views/decorators/cache.py",
>  line 89, in _wrapped_view_func
> response = view_func(request, *args, **kwargs)
> 
>   File 
> "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/admin/sites.py",
>  line 202, in inner
> return view(request, *args, **kwargs)
> 
>   File 
> "/app/.heroku/python/lib/python2.7/site-packages/django/utils/decorators.py", 
> line 25, in _wrapper
> return bound_func(*args, **kwargs)
> 
>   File 
> "/app/.heroku/python/lib/python2.7/site-packages/django/utils/decorators.py", 
> line 91, in _wrapped_view
> response = view_func(request, *args, **kwargs)
> 
>   File 
> "/app/.heroku/python/lib/python2.7/site-packages/django/utils/decorators.py", 
> line 21, in bound_func
> return func(self, *args2, **kwargs2)
> 
>   File 
> "/app/.heroku/python/lib/python2.7/site-packages/django/db/transaction.py", 
> line 223, in inner
> return func(*args, **kwargs)
> 
>   File 
> "/app/.heroku/python/lib/python2.7/site-packages/django/db/transaction.py", 
> line 217, in __exit__
> self.exiting(exc_value, self.using)
> 
>   File 
> "/app/.heroku/python/lib/python2.7/site-packages/django/db/transaction.py", 
> line 281, in exiting
> commit(using=using)
> 
>   File 
> "/app/.heroku/python/lib/python2.7/site-packages/django/db/transaction.py", 
> line 152, in commit
> connection.commit()
> 
>   File 
> "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/__init__.py",
>  line 241, in commit
> self._commit()
> 
>   File 
> "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py",
>  line 242, in _commit
> six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), 
> sys.exc_info()[2])
> 
>   File 
> "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py",
>  line 240, in _commit
> return self.connection.commit()
> 
>   File 
> "/app/.heroku/python/lib/python2.7/site-packages/newrelic-1.10.0.28/newrelic/hooks/database_dbapi2.py",
>  line 68, in commit
> return self._nr_connection.commit()
> 
> IntegrityError: insert or update on table "django_admin_log" violates foreign 
> key constraint "django_admin_log_user_id_fkey"
> DETAIL:  Key (user_id)=(2) is not present in table "auth_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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

Peter of the Norse
rahmc...@radio1190.org



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




Re: How to make django's mysql connections to use utf8mb4 ?

2013-02-18 Thread Peter of the Norse
Triple check your encoding type on the database and table. MySQL is 
often stupid about encoding, and when Django tries to do the right 
thing, it fails. I once converted a MySQL database from PHP to Django, 
and ran into a similar problem. Everything on the old database was 
marked Latin1, but web browsers were treating it as UTF-8. MySQL was 
more than happy to store invalid data, but when it came time to view the 
data with Django, all we got were random characters and question marks. 
They were trying to convert Latin1 into UTF-8 and failing. phpMyAdmin 
did the wrong thing too.


On 1/24/2013 12:59 AM, Adrián Espinosa wrote:

Hello,

I struggled with this once, although not through Django. I tried a lot 
of things, and I couldn't get MySQL to properly store emojis, or 
japanese/chinese characters for example.


As my project was just starting, I switched to postgresql, and it just 
worked. I did nothing fancy to get it to work and I have succesfully 
stored all kind of characters.


I'm also interested in the right solution for MySQL, but if you don't 
want to spend a lot of time or anything else, you might want to try 
with postgresql.


Best regards

On Wednesday, January 23, 2013 10:07:07 PM UTC+1, Chen Xu wrote:

I saved some Emoji icons to MySQL Database,the icons have been
saved correctly. Since I can see them from MySQL Shell when I type
'select message_text from messages'

However, when I do Message.object.get(ph=5).message_text, it shows
me a bunch question marks.

Could someone please help?

Thanks

-- 
⚡ Chen Xu ⚡


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

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.


--
Peter of the Norse

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




Re: Object composition in django

2013-02-17 Thread Peter of the Norse
Have you tried using unique_together? You could add unique_together = ( 
('type', 'producer',), ) to your Address model. There really isn't any way for 
the default admin to edit a second table at the same time. 

https://docs.djangoproject.com/en/1.4/ref/models/options/#unique-together 

On Feb 14, 2013, at 8:42 AM, Ray Hatfield wrote:

> Thanks, but I've omitted related_name and I've used distinct related_names 
> and gotten the same errors. I don't want to reuse addresses. The one-to-one 
> relationship you describe is precisely what I'm trying to do.
> 
> On Feb 14, 2013, at 1:32 AM, Jani Tiainen  wrote:
> 
>> Hi,
>> 
>> You're trying to setup one-to-one relationship.
>> 
>> It means that producer.mailing_address does have exactly one unique Address 
>> entity. Same goes for physical_address.
>> 
>> What you want is really ForeignKey to address which means that you reuse 
>> addresses to multiple producer.mailing_address.
>> 
>> Then you can omit related names, or like someone suggested use different 
>> related names for both fields.
>> 
>> 13.2.2013 21:25, Ray Hatfield kirjoitti:
>>> Hi,
>>> 
>>> I have a model which requires two addresses: a mailing address and a
>>> physical address. From an OO perspective it makes sense to have an
>>> Address class and the Producer to have Address instances as properties,
>>> but I can't seem to achieve this in django while still being able to
>>> edit the addresses inline as part of the Producer admin.
>>> 
>>> I've tried this sort of thing:
>>> 
>>> class Address( models.Model ):
>>>street = models.CharField( ... )
>>># city state zip, etc.
>>> 
>>> class Producer( models.Model ):
>>>mailing_address = models.OneToOneField( Address, related_name='+' )
>>>physical_address = models.OneToOneField( Address, related_name='+' )
>>> 
>>> but when I attempt to inline the addresses in the django admin I run
>>> into trouble. I get errors like:
>>> 
>>>  has no ForeignKey to >> 'producers.models.Producer'>
>>> 
>>> (This error is true, of course. But I was under the apparently erroneous
>>> impression that including related_name='+' would prevent django from
>>> setting up the reverse relationship.)
>>> 
>>> I realize I could add a foreign key to Address to associate it with a
>>> specific Producer but this feels backwards to me. An Address shouldn't
>>> need to know whether it's for a Producer or some other object. It's just
>>> an address.
>>> 
>>> I've been banging my head on this for far too long. Advice?
>>> 
>>> --
>>> 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?hl=en.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>> 
>>> 
>> 
>> 
>> -- 
>> Jani Tiainen
>> 
>> - Well planned is half done and a half done has been sufficient before...
>> 
>> -- 
>> 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?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+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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 

Peter of the Norse
rahmc...@radio1190.org



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




Re: django generate pdf with tables and charts

2013-02-13 Thread Peter of the Norse
Django doesn’t run Javascript, that’s done in the browser. If you really want 
to have JS processing you’ll have to open a web browser and then print to PDF.

On Feb 10, 2013, at 9:10 AM, Jaimin Patel wrote:

> I am trying to generate pdf using django template, also need some support of 
> javascript code. I have tried PISA, ReportLib and wkhtmltopdf but it seems 
> that it doesn't wait for Javascript. 
> 
> Can someone suggest good solution or example?
> 

Peter of the Norse
rahmc...@radio1190.org



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




Re: initial argument in forms not working for me

2013-01-31 Thread Peter of the Norse
Weird HTML formatting in your message. Plain text fixes things.

The issue is the capital P in initial='Public'. The choices list looks like 
(value stored in the database, value displayed to the user). The choices that 
the RadioSelect looks for from the datase are 'public' and 'private'. 'Public' 
doesn't match either of them.

On Jan 27, 2013, at 10:44 PM, Nikhil Verma wrote:

> Sorry I made a typo in last email .
> 
> Can anybody explain what mistake i am  doing ?
> 
> Hi 
> 
> I am using django 1.4.3 and have a field in form
> 
> 
>  PROFILE_TYPE = (
> ('public', 'Public'),
> ('private', 'Private'),
> )
>  profile_type = forms.CharField(max_length=10,
>widget=RadioSelect(choices=PROFILE_TYPE),
>initial='Public',
>required=False
>)
> 
> Thanks 
> 
> 
> 
> On Mon, Jan 28, 2013 at 11:05 AM, Nikhil Verma  
> wrote:
> Hi 
> 
> I am using django 1.4.3 and have a field in form
> 
> 
>  PROFILE_TYPE = (
> ('public', 'Public'),
> ('private', 'Private'),
> )
>  profile_type = forms.CharField(max_length=10, widget=RadioSelect
>(choices=PROFILE_TYPE),
>initial='Public',
>required=False
>)
> 
> I want that when i open this form the radio button with choice public should 
> be pre selected.
> Can anybody explain what mistake you are doing ?
> 
> Thanks
> 
> 
> -- 
> Regards
> Nikhil Verma
> +91-958-273-3156
> 
> 
> 
> -- 
> Regards
> Nikhil Verma
> +91-958-273-3156
> 
> -- 
> 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.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

Peter of the Norse
rahmc...@radio1190.org



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




Re: Polls tutorial receive object not object representation

2013-01-31 Thread Peter of the Norse

On Jan 27, 2013, at 6:53 PM, Sayth Renshaw wrote:

> Hi
> 
> Just seeking a little clarification.
> 
> In the Polls tutorial we get this section.
> 
> >>> p = Poll.objects.get(pk=1)
> 
> # Display any choices from the related object set -- none so far.
> >>> p.choice_set.all()
> []
> 
> # Create three choices.
> >>> p.choice_set.create(choice_text='Not much', votes=0)
> 
> >>> p.choice_set.create(choice_text='The sky', votes=0)
> 
> >>> c = p.choice_set.create(choice_text='Just hacking again', votes=0)
> 
> # Choice objects have API access to their related Poll objects.
> >>> c.poll
> 
> 
> # And vice versa: Poll objects get access to Choice objects.
> >>> p.choice_set.all()
> [, , ]

> Now the only thing is that when I call p.choice_set.all() I don't get the 
> representation 'The sky' or 'Just Hacking again' . I receive choice object 
> itself. Is this normal?

> In [14]: c = p.choice_set.create(choice_text='Just Hacking again', votes=0)
> 
> In [15]: c.poll
> Out[15]: 
> 
> In [16]: p.choice_set.all()
> Out[16]: [, ,  object>,  ject>]
> 
> Thanks 
> Sayth

Did you add an __unicode__ method to Choice class? That's how you get the 
pretty representations of objects. 
https://docs.djangoproject.com/en/1.4/intro/tutorial01/#playing-with-the-api

Peter of the Norse
rahmc...@radio1190.org



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




Re: Setting urls from project

2013-01-18 Thread Peter of the Norse
This is exceptionally wrong! If you put a $ in the pattern, it will only 
match those urls. For example the uri http://localhost/cadastro/56/ 
won't match anything. Only http://localhost/cadastro/ would match, and 
if you're including another url file, I doubt that's what you want.


On 12/24/2012 12:01 AM, Matthew Edwards wrote:
I'm still learning Django myself, but I believe each url should end 
with '$' in order to stop the regex match at the forward slash.


So your new URIs would be:
url(r'^cadastro/$', include('contact.urls')),
url(r'^contato/$', include('contact.urls')),
url(r'^sobre/$', include('contact.urls')),
url(r'^admin/$', include(admin.site.urls)),

I hope that solves your problem.

On Sunday, December 23, 2012 9:19:50 AM UTC-8, Filipe Manuel wrote:

I wish that when from accessing localhost:8000/cadastro he showed
a form to register, but all the urls I click redirects to the same
page. I wonder how pegging the url with the url of the
application. I've Identified the error, all urls design guide for
single views of the application, but do not know how to fix it.

My code: http://dpaste.com/850276/

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

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.



--
Peter of the Norse

--
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: HTML Source on Browser Rendering

2013-01-13 Thread Peter of the Norse
You're looking at the wrong thing. The  tags were added by your browser. 
Chrome and Firefox show cleaned up HTML in firebug/web inspector. In the case 
of a bad MIME type, it treats it as text, and wraps everything in HTML for 
displaying. When people say to check the Content-Type header, you should look 
in the network tab.

On Jan 9, 2013, at 1:57 AM, Ryoichiro Kamiya wrote:

> It's been resolved. The following mimetype property in views.py added the 
>  tags.
> 
> return render_to_response('prayer/service_index.html', datadict, 
> mimetype="application/json; charset=utf-8")
> 
> Thanks,
> Ryo
> 
> On Wednesday, January 9, 2013 11:07:14 AM UTC+9, Ryoichiro Kamiya wrote:
> Thanks all for seeing this thread.
> 
> With further experiment, the result shows the HTML source with  tag even 
> after emptying the contents of the Django template file. When I tested it in 
> various browsers, the browser automatically added basic HTML structure with 
>  tag on top of my contents. I compared the line endings and encoding 
> with another page that working correctly, but couldn't find any difference.
> 
> I'll mark this as closed as it seemed not an issue resulting from Django.
> Everyone, thanks for replying to my question. Have a nice day!
> 
> Regards,
> Ryo
> 
> On Tuesday, January 8, 2013 2:31:16 PM UTC+9, djangobie wrote:
> Than  is the issues, as it 'll display the content (inside it) as it is 
> .. making it preformated.
> can't guess how you got your code wrapped in it in the first place.
> 
> Thanks
> 
> On Tuesday, January 8, 2013 6:29:53 AM UTC+5, Ryoichiro Kamiya wrote:
> Thanks jjmutumi, stauros!
> 
> I am not using "autoescape" tag in my template. Thanks.
> 
> I am just checking the source on the back of HTML source displayed with 
> Firebug as jmutumi suggested.
> It seemed an auto-inserted  tag before & after the source. (Please find 
> the attached. thanks)
> 
> Any ideas how this can be added?
> 
> Ryo
> 
> On Monday, January 7, 2013 5:22:30 AM UTC+9, stauros wrote:
> Hello,
> maybe any "autoescape"  template tags on the wrong spot?
> 
> 
> On Sun, Jan 6, 2013 at 9:46 PM, Joseph Mutumi  wrote:
> Hello,
> 
> I think you should also check the 'Content-Type' being received client-side
> in the HTTP headers. You can use something curl or Firebug.
> 
> 
> On Sun, Jan 6, 2013 at 1:40 PM, Ryoichiro Kamiya  
> wrote:
> Hi,
> 
> I'm testing Django template rendering in development environment, but one of 
> the page shows HTML source (after all Django tag executed) instead of HTML.
> 
> 1. Content Type
> The first thing I check is the Content Type but it's correctly set up (and 
> it's in header template and shared with other pages that show contents 
> correctly.
> 
> 
> 
> 
> 
> When I copied & pasted to another template and it works.
> 
> 2. Browser
> I checked it in another browser (i.e. Chrome) but it returned the same result.
> 
> 3. Reboot runserver
> also it didn't change the output.
> 
> Is there anything else I should check?
> Thanks in advance.
> 
> Regards,
> Ryo
> 
> -- 
> 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/-/FyjKgMAxm0YJ.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users...@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...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 
> 
> -- 
> Stavros
> 
> -- 
> 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/-/52PmLUnVVSIJ.
> 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.

Peter of the Norse
rahmc...@radio1190.org



-- 
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: Multiple model inheritance

2013-01-05 Thread Peter of the Norse
I’m not sure that’s possible. Even abstract Models do magic in the background. 
Specifically there's the _meta class attribute that gets inherited. If you were 
to try it, only one of the _metas would be included.

On Dec 31, 2012, at 6:12 AM, Mattias Linnap wrote:

> Hi all,
> 
> I would like to define multiple abstract base models with small set of
> fields each. The "real" models inherit from multiple mixins to add the
> fields.
> 
> For example:
> class Taggable(?):
>tag = models.CharField()
> class Visible(?):
>visible = models.BooleanField()
> class SomeFullModel(?, Taggable, Visible):
>otherfield = models.CharField()
> 
> With this use case:
> * should the abstract models inherit from models.Model, or be a plain
> Python class inheriting from object?
> * should all or any of the abstract models have a class Meta with
> abstract=True?
> * should the final real model inherit from models.Model (probably
> required if all the mixins are plain classes), or inherit from the
> first mixin that is an abstract model?
> * does the order of the base classes in SomeFullModel matter?
> 
> Thanks,
> 
> Mattias
> 
> -- 
> 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.
> 

Peter of the Norse
rahmc...@radio1190.org



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



django-users@googlegroups.com

2013-01-05 Thread Peter of the Norse
eld(unique=False,blank=True,null=True)
>   year=models.CharField(max_length=4,unique=False,blank=True,null=True)
>   location=models.TextField(unique=False,blank=True,null=True)
>   status=models.CharField(unique=False,max_length=20)
>   mk=models.CharField(max_length=8,unique=True,primary_key=True)
>   period=property(period) 
>   language = models.CharField(unique=False,max_length=30)
>   #objects=MenuManager()
>   # def __unicode__(self):
> # return restaurant
> # class MenuPageManager(models.Manager):
> # def create_MenuPage(self,mk,menu_id):
> # menuPage = self.create(mk=int(mk),menu_id=int(menu_id))
> # return menuPage
> class MenuPage(models.Model):
>   mk=models.CharField(max_length=10,unique=True)
>   menu_id=models.OneToOneField("Menu",to_field='mk')
>   #objects=MenuPageManager()
> # class DishManager(models.Manager):
> # def create_Dish(self,name,mk):
> # dish = self.create(name=str(name),mk=int(mk))
> # return dish
> # def get_by_natural_key(self,name):
> # return self.get(name=name)
> class Dish(models.Model):
>   def __unicode__(self):
>   return self.name
>   full_name = models.TextField()
>   name=models.CharField(unique=True,max_length=255)
>   mk=models.CharField(max_length=10,unique=True)
>   #classification = models.OneToOneField("Classification",to_field="d")
>   #objects=DishManager()
>   # def __unicode__(self):
> # return name
> # class ClassificationManager(models.Manager):
> # def create_Classification(self,dish,classification,mk):
> # classification = 
> self.create(dish=str(dish),classification=str(classification),mk=int(mk))
> # return classification
> class Classification(models.Model):
>   def __unicode__(self):
>   if self.classification:
>   return self.classification
>   else:
>   return "none"
>   dish=models.OneToOneField('dish',to_field='name')
>   classification=models.CharField(unique=False,max_length=9)
>   mk=models.CharField(max_length=10,primary_key=True)
> 
> Here, if it's relevant, is the template for my search page:
> 
> {% extends "base.html" %}
> {% block style %}
> 
> {% endblock %}
> {% block java %}
> 
> {% endblock %}
> {% block title %}Search{% endblock %}
> {% block head %}Search{% endblock %}
> {% block content %}
> {% autoescape off %}
> 
>   
>   
>   
>   {% for form in formset.forms %}
>   
>   {{ form.row }}
>   {{ form.query }}
>   {{ form.bools }}
>   
>   {% endfor %}
>   
>   
>   {{ formset.management_form }}
>   
>   
> 
> {% if formset.errors or errors %}
> 
>   The following errors were encountered while trying to submit your 
> search:
>   {% for x,y in formset.errors.items %}
>   {{ x }} : {{ y }}
>   {% endfor %}
>   {{ errors }}
> 
> {% endif %}
> 
>   Searching by dish names, locations, and restaurants is 
> case-insensitive.
>   Searching by course uses  case-insensitive exact matching. Valid 
> courses are Appetizer, Main, and Dessert.
>   Years should be entered . Five-year periods span either the 
> first or second half of a decade, and should be entered -. Example 
> valid five-year periods are 1900-1905, 1995-2000, etc.
>   Regular expression search follows MySQL regular expression syntax, 
> as described http://dev.mysql.com/doc/refman/5.1/en/regexp.html"; 
> target="_blank">here.
> 
> 
> {% endautoescape %}
>  
> {% endblock %}
> 
> {% block footer %}
> 
>   NOTE: This site and the information it contains are still in 
> development. Some information may be missing or inaccurate.
> 
>   
>   Created and maintained by Sam Raker 
> and Rachel Rakov
>   
>   Data graciously provided by http://menus.nypl.org"; 
> target="_blank">What's on the Menu?
>   
> {% endblock %}
> 
> 
> -- 
> 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/-/089Rexbg5jYJ.
> 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.

Peter of the Norse
rahmc...@radio1190.org



-- 
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: ImportError at/ No module name

2012-12-24 Thread Peter of the Norse
The error is pretty clear: It can't find 
/home/username/djangosites/djangopractice/blog/__init__.py Make sure that file 
exists. Try running `manage.py shell` and `import blog`. Also, make sure that 
the files are readable by your web server, e.g. apache.

On Dec 20, 2012, at 9:55 PM, djangobie wrote:
> ImportError at /
> 
> No module named blog
> Request Method:   GET
> Request URL:  http://localhost:8000/
> Django Version:   1.4.3
> Exception Type:   ImportError
> Exception Value:  
> No module named blog
> Exception Location:   
> /usr/local/lib/python2.7/dist-packages/django/utils/importlib.py in 
> import_module, line 35
> Python Executable:/usr/bin/python
> Python Version:   2.7.3
> Python Path:  
> ['/home/username/djangosites/djangopractice',
>  '/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/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-storage-protocol']

Peter of the Norse
rahmc...@radio1190.org



-- 
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: count resulting rows in sliced valuesqueryset

2012-11-26 Thread Peter of the Norse
I did some research on windowing functions since your post. They tend to be 
slower since they ignore optimizations. For example, when using count(*), 
indexes are used whenever possible to avoid hitting the table data and outer 
joins are ignored altogether.  And limited searches quit as soon as they reach 
the proper count.

One case where it might be faster to combine them is looking up the last page. 
For example:
count = qs.count()
qs = qs[ count-100 : count ]

When I run my slow query on that, I get 0.2 sec + 1.9 sec. YMMV. That’s why 
there’s https://docs.djangoproject.com/en/1.5/ref/models/querysets/#reverse 

On Nov 24, 2012, at 4:06 PM, ?manu* wrote:

> On Saturday, November 24, 2012 8:03:06 AM UTC+1, Peter of the Norse wrote:
> On Nov 21, 2012, at 3:53 AM, ?manu* wrote: 
> 
> > Suppose I have a queryset qs. For paginating purposes I need to do 
> > something like: 
> > 
> > count = qs.count() 
> > qs = qs[0:100] 
> > 
> > Unfortunately this executes the query twice, which I don't want. 
> 
> Are you sure? This is such a common pattern that I suspect that it’s not 
> slower than making it into one query. I ran some tests on the slowest query I 
> have, and the two statements were faster than trying to combine them. 0.2 + 
> 1.5 sec vs. 1.9 sec. 
> 
> You are right! (thanks also to Javier). It is not clear to me how it is 
> possible but effectively it seems that the two queries are not slower than a 
> single one...
> 
> Thank you also for the other answers.
> 
> E.
>  

Peter of the Norse
rahmc...@radio1190.org



-- 
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: overwrite field value in subclasses

2012-11-25 Thread Peter of the Norse
Foo.myfield is 0, but when you created a new models.Field object in the 
abstract class, it did some deep magic. There’s also Foo._meta.fields which has 
the old myfield in it. The only thing you can do is create a new myfield with 
default=0 and editable=False.

On Nov 23, 2012, at 8:40 AM, Emmanuel Jannetti wrote:

> Hi all,
> 
> One piece of my model is as follow :
> 
> class UpperAbstract(models.Model):
>   CHOICE_A = 0
>   CHOICE_B = 1
>   CHOICE_C = 2
>   myfield = 
> models.PositiveSmallIntegerField(choices=((CHOICE_A,'A'),(CHOICE_B,"B"),(CHOICE_C,"C")),blank=False)
>   class Meta:
>   abstract = True
> 
> class Foo(UpperAbstract):
>   myfield = UpperAbstract.CHOICE_A
> 
> 
> 
> I am expecting any instance of Foo being created, to have 'myfield' always 
> and "automatically" set to UpperAbstract.CHOICE_A
> In my test the created object as null value and saving it is refused on 
> IntegrityError because 'myfield' cannot be None
> 
> thank in advance for any help.
> regards
> 
> manu
> 

Peter of the Norse
rahmc...@radio1190.org



-- 
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: count resulting rows in sliced valuesqueryset

2012-11-23 Thread Peter of the Norse
On Nov 21, 2012, at 3:53 AM, ?manu* wrote:

> Suppose I have a queryset qs. For paginating purposes I need to do something 
> like:
> 
> count = qs.count()
> qs = qs[0:100]
> 
> Unfortunately this executes the query twice, which I don't want. 

Are you sure? This is such a common pattern that I suspect that it’s not slower 
than making it into one query. I ran some tests on the slowest query I have, 
and the two statements were faster than trying to combine them. 0.2 + 1.5 sec 
vs. 1.9 sec.

> I can use postgresql windowing function like that:
> 
> qs = q.extra(select = {'count': 'COUNT(*) OVER()'})
> 
> to get the 'count' attribute on every object. So far this is very nice. The 
> problem is that my queryset qs is actually a ValuesQueryset, i.e. a queryset 
> build with .values(...).annotate(...). In this case the extra select field is 
> ignored (as reported in the documentation). This makes sense because even in 
> postgres it seems not possible to mix window functions with "group by" 
> clauses. The solution with raw SQL is the use of a subquery. I can get the 
> correct results with the following query, where I enclose the sql produced by 
> django in a subquery:
> 
> sql = 'SELECT COUNT(*) OVER() , subquery.* FROM (%s) AS subquery' % qs.query
> 
> Now the questions:
> 
> 1. in this snippet qs.query is converted to string. The documentation says 
> that parameters in the resulting query string are not correctly escaped, so 
> maybe I should take care of SQL injection? How do I get correct escaping of 
> parameters?

You don't. The problem is qs.query is constructed for your convenience, it’s 
not what’s passed to the database. For a query like User.objects.fiter(id=5), 
the underling DB call looks like cursor.execute("SELECT * FROM user WHERE id = 
%s", (5,)). That is, the SQL has placeholders for the values, and the values 
are passed separately. Django doesn't actually escape the values, it just lets 
the DB backend do it. It’s much safer and a little faster to do it that way. 
Look at qs.query.sql_with_params()

> 2. Is it possible to re-attach the sql statement to my ValuesQuerySet? To 
> keep the rest of the code unchanged, I need to modify qs so that it executes 
> the new raw query. However I don't see how to construct a ValuesQueryset with 
> a raw SQL code...

sql, params = qs.query.sql_with_params()
s = ValuesQuerySet.objects.raw('SELECT COUNT(*) OVER() , subquery.* FROM 
('+sql+') AS subquery', params);
see https://docs.djangoproject.com/en/1.4/topics/db/sql/

Let me know if that works.

Peter of the Norse
rahmc...@radio1190.org



-- 
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: Should we have a database independent SQL like query language in Django?

2012-11-18 Thread Peter of the Norse
It sounds to me like you are saying “Django ORM should be better”, which is 
true. But the entire point of SQL is that it’s a common database language. You 
don’t know what it was like back in the day when every vendor had a different 
language. Most queries that use a common feature set work fine on ProstgreSQL, 
MySQL, SQLite, and Oracle. I can only think of one feature that’s written 
differently in MySQL, SQLite, and Postgres. The real problem comes from missing 
features in one than another. That multiple join query you mention: I’m almost 
certain that it will work with everything but MSSQL.

On Oct 6, 2012, at 8:38 AM, Yugal Jindle wrote:

> Note :
> 
>  - I know we have `Django ORM` already that keeps things database independent 
> and converts to the database specific `SQL` queries.
>  - Once things starts getting complicated it is preferred to write `raw SQL` 
> queries for better efficiency.
>  - When you write `raw sql` queries your code gets trapped with the database 
> you are using.
>  - I also understand its important to use the full power of your database 
> that can-not be achieved with the `django orm` alone.
> 
> My Question :
> 
>  - Until I use any database specific feature, why should one be trapped with 
> the database.
>  - For instance :
> 
> We have a query with multiple joins and we decided to write a raw sql
> query. Now, that makes my website `postgres` specific. Even when I
> have not used any postgres specific feature.
> 
> I feel there should be some `fake sql` language which can translate to any 
> database's sql query. Even Django's ORM can be built over it. So, that if you 
> go out of ORM but not database specific - you can still remain database 
> independent.
> 
> I asked the same question to `Jacob Kaplan Moss` (In person) :
> 
>  - He advised me to stay with the database that I like and endure its whole 
> power, to which I agree. But my point was not that we should be `database 
> independent`.
>  - My point is we should be database independent until we use a database 
> specific feature.
> 
> 
> Please explain, why should be there a `fake sql` layer over the actual sql ?
> 
> 
> -- 
> 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/-/cQW4Vpc9ueYJ.
> 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.

Peter of the Norse
rahmc...@radio1190.org



-- 
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: Autoescape of & char ignoring safe filter

2012-11-16 Thread Peter of the Norse

I know this is months old, but I've been working on my back log.

First of all, you should be using & in your URLs. They will get 
unescaped by the browser and show up as & when you click the link.


This is so commonly overlooked that the browser will automatically 
escape them when loading. Then firebug and webkit inspector will show 
the source with & even if they aren't in the source. So the followup 
question is: where are you getting the template results from? Make sure 
that you're doing "show source" and not just looking at the DOM 
inspector. I suspect that's what's happening since some closing tags are 
missing from the template result.


On 10/3/2012 11:17 AM, Marc Serra wrote:
Laxmikant I think you didn't understand my point. I don't want it 
escaped, and escape marks it for escaping. I want to output the 
contents of database RAW, without escaping. Safe filter does this but 
I found the weird exception of &, what messes with urls with 
parameters on them.


Regards,
Marc Serra

El dimecres 3 d’octubre de 2012 6:25:38 UTC+2, Laxmikant Gurnalkar va 
escriure:


>>>I have not used *safe*  ever. But use *escape* this works for me.

On Wed, Oct 3, 2012 at 9:54 AM, Laxmikant Gurnalkar
> wrote:

Hi,
I have not used *sace*  ever. But use *escape* this works for me.
https://docs.djangoproject.com/en/1.0/ref/templates/builtins/#escape


Cheers
*Laxmikant G.*



On Wed, Oct 3, 2012 at 4:06 AM, Marc Serra > wrote:

Hi, i'm trying to output raw html content form the
database on the website, so i use the safe filter on the
variable. All html code is displayed correctly except the
ampersand that are escaped ignoring the safe filter, or It
seems to me.

I also tried to use a templatetag  with the mark_safe
function with the same outcome.

Here an example:

Source in database:

http://www.youtube.com/v/Uq8zzBW9hlc&hl=en&fs=1&hd=1  ">http://www.youtube.com/v/Uq8zzBW9hlc&hl=en&fs=1&hd=1  " type="application/x-shockwave-flash" 
allowscriptaccess="always" allowfullscreen="true" width="560" height="340">

On template with |safe filter (notice "&" replacement with "&"):

http://www.youtube.com/v/Uq8zzBW9hlc&hl=en&fs=1&hd=1  ">http://www.youtube.com/v/Uq8zzBW9hlc&hl=en&fs=1&hd=1  " 
type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" height="340" width="560">



You know what can be the reason to this behaviour and how to solve 
it?

Thank you,
Marc Serra




--
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: 'NoneType' object has no attribute 'datetime' bug?

2012-08-14 Thread Peter of the Norse
I had a similar problem in one of my views. It looked like:

from X import y

def my_func():
foo = y.baz()
...
y = foo + bar;

Since I was assigning to y later in the function, “y” represented a local 
variable throughout the function. Somewhere you have “datetime =”, but it might 
be later in the method.

On Jul 14, 2012, at 6:01 AM, dobrysmak wrote:

> Hi guys,
> i have run into this.
> 
> Traceback:
> File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in 
> get_response
>   111. response = callback(request, *callback_args, 
> **callback_kwargs)
> File 
> "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/decorators.py" in 
> _wrapped_view
>   20. return view_func(request, *args, **kwargs)
> File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in 
> _wrapped_view
>   91. response = view_func(request, *args, **kwargs)
> File "/home/user/dev/xyz/coupon/views.py" in enter_game
>   69. Coupon(coupon=coupon, player=player, 
> credicts=credicts).save()
> File "/home/user/dev/xyz/coupon/models.py" in save
>   253. self.coupon.close_coupon()
> File "/home/user/dev/xyz/coupon/models.py" in close_coupon
>   78. current_date = datetime.datetime.now()
> 
> Exception Type: AttributeError at /wejdz-do-gry/49/
> Exception Value: 'NoneType' object has no attribute 'datetime'
> Request information:
> GET: No GET data
> 
> and the cuntion "close_coupon" looks like this
> 
> class Coupon(models.Model):
> .
> 
> .
> .
> end_date= models.DateTimeField(default=None, null=True, blank=True)
> 
> 
> def close_coupon(self):
> 
> current_date = datetime.datetime.now()
> today = datetime.datetime.combine(datetime.date.today(), 
> datetime.time(19,30))
> 
> .
> .
> end_date = current_date
> 
> Don't know if that's a bug. Does anyone know how to deal with this issue? 
> Cheers!

Peter of the Norse
rahmc...@radio1190.org



-- 
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: setting up new django project

2012-06-20 Thread Peter of the Norse

On 5/27/2012 8:53 PM, xaegis wrote:

Hello, this is my first time posting to a list!
  I am running python 2.7 with django 1.4 installed on Ubuntu 12.04
I am having trouble creating new projects with django. Whenever I use
the command:
Code:

sudo /usr/local/lib/python2.7/dist-packages/django/bin/django-admin.py
startproject cms

I get errors or permission denied messages but if I use:
Code:

django-admin.py startproject cms

Everything seems to work correctly. I know at some point I created a
sym link in:
Code:

/usr/local/bin

but is this the proper way to do this? Should I be using the full path
instead? Also, why is django found in dist-packages instead of site-
packages in the python directory? The books I am using are telling me
the python files should be located in site-packages.
You are most likely getting that error message because you have more 
than one copy of Django installed. Find out what version of 
django-admin.py you're using by doing:


$ whereis django-admin.py

It's possible that you installed Django using the system tools (apt-get, 
rpm, etc.) and that has preference over the one in /usr/local/bin.



I also noticed that django "startproject" created two directories
called "cms" one nested inside the other. Is this the default
behavior, and why?
It is as of 1.4. The things inside of cms/cms tend not to be that 
portable between sites while all of the app directories should show up 
as cms/app_1.

I am also having trouble setting up the sqlite3 back-end and I keep
getting the error:

Code:
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/
sqlite3/base.py", line 281, in _cursor
 self._sqlite_create_connection()
   File "/usr/local/lib/python2.7/dist-packages/django/db/backends/
sqlite3/base.py", line 271, in _sqlite_create_connection
 self.connection = Database.connect(**kwargs)
pysqlite2.dbapi2.OperationalError: unable to open database file


Thanks in advance.



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



Re: Python FAQ: Webdev

2012-06-07 Thread Peter of the Norse

On May 12, 2012, at 11:49 PM, Nick Apostolakis wrote:

> On 13/05/2012 07:32 πμ, Peter Murphy wrote:
>> All,
>> 
>> The site recommends "Flask" by the way - not Django. The author thinks
>> it is too heavyweight for his or her uses. But there seems to be a lot
>> of ideas in the article about how to make a framework that seem to be
>> captured in Django.
>> 
>> Best regards,
>> Peter
>> 
>> [* http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ ]
>> 
>>   
> An interesting article, I didn't realize Django was too "heavy weight".
> I also didn't know about Flask and Pyramid either.

There's a large group of programmers, especially in Python, that loves "Do one 
thing, and do it well". If you don't need database support, then half of Django 
goes unused. If you do need to save data, then you'll love ModelForms. I like 
that Django has everything I need and that they all work together. But if you'd 
rather use MongoDB, then it's every difficult. 

Peter of the Norse
rahmc...@radio1190.org



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



Re: How to perform a simple search ignoring characters with accents (á, é, í, ó, ú)

2012-06-04 Thread Peter of the Norse
One possibility is to use MySQL. By default it indexes things so that a, á, and 
À are the same thing. There are some gotchas though: you have to make sure that 
it’s using an appropriate character set for the languages you’re using. (UTF-8 
is a good choice.) There’s not a good similar solution for PostgreSQL. While it 
is possible to write a function, and create an index on that function, I 
haven’t found a way of searching on that index in Django. If anyone knows of a 
way to do it, I’d love to here it.

On Jun 1, 2012, at 11:41 AM, Kurtis Mullins wrote:

> Maybe you could just build a simple index? It'd basically be a set of 
> keywords, each with a set of matching books.
> So in your example, you'd have two keywords:
> 
> hola (with accent) -> book1, book2, etc..
> hola (without accent) -> (same as previous)
> 
> And then just write some sort of functionality to run through your data and 
> index it to a table. I can't vouch that this is the best approach - but I 
> think it'd at least solve the problem.
> 
> On Fri, Jun 1, 2012 at 1:03 PM, Joni Bekenstein  
> wrote:
> I need to do a simple search ignoring some characters with accents. The idea 
> would be that "hola" matches the search term "holá".
> 
> What I'm currently doing is adding a CharField to my model to store the 
> searchable term. For example:
> 
> class Book(models.Model):
>   title = models.CharField(max_length=100)
>   searchable_title = models.CharField(max_length=100)
> 
> When I save a Book I'll replace the accented characters in title with their 
> non-accented counterparts and store the result in searchable_title. The, I'll 
> also do the same thing with the search term before actually doing the query.
> 
> I don't like this approach because if I need to add more searchable fields 
> things start getting noisy in my models.
> 
> Any ideas?
> 
> -- 
> 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/-/tdIUkptWpZgJ.
> 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.

Peter of the Norse
rahmc...@radio1190.org



-- 
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: Adding values to formdata of ModelForm before saving

2012-06-03 Thread Peter of the Norse
Super is one of python’s greatest mistakes. 
http://docs.python.org/library/functions.html#super The form is
class class_name(parent_class):
def method(self, *args, **kwargs):
super(class_name, self).method(*args, **kwargs)

It’s better in Python 3, but Django hasn’t been ported over yet.

On Jun 1, 2012, at 10:03 AM, Schmidtchen Schleicher wrote:

> Thank you for your effort, as far as I can see you understood my problem 
> right and your solution could work... if there wouldn't be that error:
> TypeError at /kalender/1/new_termin/
> 
> super(type, obj): obj must be an instance or subtype of type
> 
> Termin is a model class, NewTerminForm is a modelformclass (Termin is german 
> for appointment). This is the first time I use super() so I don't know how to 
> solve this problem
> 
> 
> Am Freitag, 1. Juni 2012 02:48:04 UTC+2 schrieb Kurtis:
> One minor edit to that:
> form.save(request) -> form.save(request, kalender)
> 
> On Thu, May 31, 2012 at 8:47 PM, Kurtis Mullins  
> wrote:
> Hey,
> 
> I tried re-writing your view and form for you -- but I ran into a snag. I 
> don't read German so other than code-wise (and a couple of obvious words, 
> like kalender and participants) I'm not really sure what you're trying to 
> accomplish.
> 
> I do see one obvious issue, though. Participants is a many-to-many field in 
> your Model and you're also using the same attribute in your form. Here's 
> something you could try in your form and view:
> 
> View:
> 
> if request.method == 'POST':
> form = MyForm(request.POST)
> if form.is_valid():
> form.save(request)
> 
> Form:
> -
> def save(self, request, kalender, commit=True):
> 
> # Get an Instance of the Termin object.
> obj = super(Termin, self).save(commit=True)
>
> # Add the user as a participant if 'add_me' = True
> if self.cleaned_data['add_me']:
> obj.participants.add(request.user)
> 
> # Set the Calendar, Save, and return
> obj.in_calendar = kalender
> obj.save()
> return obj
> 
> Hopefully I didn't just confuse you more :) Good luck!
> 
> 
> -- 
> 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/-/WyKASDjYNEgJ.
> 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.

Peter of the Norse
rahmc...@radio1190.org



-- 
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 ModelForm user best practices

2012-06-02 Thread Peter of the Norse
.post
> n.board = self.board
> n.save()
> return n
> 
> 
> I'm sure there are more ways to achive the same result.
> What are your thoughts on that ?
> 
> When should I 'hide' (by using HiddenInput() widget) ModelForm fields? when 
> should I save them directly
> in view? 
> 
> Does it all depend on needs or maybe there are some "best" standards ?
> 
> 
> -- 
> 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/-/xn6xNGKJ2CEJ.
> 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.

Peter of the Norse
rahmc...@radio1190.org



-- 
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: Error with Views on Admin and Index page

2012-05-27 Thread Peter of the Norse
Can we see your urls.py? I'm worried that you’re directing to a views.py file 
that doesn't actually exist.

On May 24, 2012, at 2:38 PM, cat123 wrote:

> No I'm not doing the Django tutorial. I'm following a couple of older
> Django books that were published circa 2009 using Django 1.1. ('m
> using Django 1.3). I did set up Staticfiles  (the Django 1.3 way, the
> best I could as a newbie, following djangoproject directions) but
> staticfiles is of course for static pages...I did create a page with
> base.html and css, and was able to view that.  Are Admin pages and the
> Index page considered staticfiles? If so, maybe I didn't set that up
> right?
> 
> 
> On May 24, 1:14 pm, Apokalyptica Painkiller 
> wrote:
>> Are you doing django's tutorial? If it is correct in which part are you?
>> 
>> 2012/5/24 cat123 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> Hi Apo:
>> 
>>> Thanks for the feedback...When I look at those links, they're both
>>> about views from apps that have been created. I haven't created any
>>> apps yet... so which Views do you think it may be talking about, and
>>> where would I look for this?
>> 
>>> On May 24, 12:14 pm, Apokalyptica Painkiller
>>>  wrote:
>>>> Hello why don't you check this two links:
>> 
>>>> http://stackoverflow.com/questions/5350241/django-import-error-that-r...
>> 
>>>> http://stackoverflow.com/questions/3496920/django-viewdoesnotexist
>> 
>>>> Good luck :)
>> 
>>>> 2012/5/24 cat123 
>> 
>>>>> I'm new to Django and recently got my very first environment set up
>>>>> (Python 2.7, Django 1.3, with Postgres 9.1.3 and virtualenv)...
>> 
>>>>> I set up everything for "Admin," (first time setup),got the LogIn
>>>>> Page. But when I logged in, instead of going to the admin screen, I
>>>>> got a message saying:
>> 
>>>>> TemplateSyntaxError at /admin/
>>>>> Caught ViewDoesNotExist while rendering. Could not import views. Error
>>>>> was: No module named views.
>> 
>>>>> I noticed I also get something similar after I uncommented the django-
>>>>> supplied index page (in urls.py) (which I have also never
>>>>> resolved...seems they may be connected?):
>> 
>>>>> ViewDoesNotExist at / Could not import hgb_project.views. Error was:
>>>>> No module named views
>> 
>>>>> Would appreciate any help anyone has to offer...
>> 
>>>>> Thanks,
>>>>> cat
>> 
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>> Groups
>>>>> "Django users" group.
>>>>> To post to this group, send email to django-users@googlegroups.com.
>>>>> To unsubscribe from this group, send email to
>>>>> django-users+unsubscr...@googlegroups.com.
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/django-users?hl=en.
>> 
>>>> --
>>>> I live each day
>>>> Like it's my last
>>>> I live for rock and roll
>>>> I never look back
>> 
>>>> I'm a rocker
>>>> Do as I feel as I say
>>>> I'm a rocker
>>>> And no one can take that away
>> 
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Django users" group.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>> 
>> --
>> I live each day
>> Like it's my last
>> I live for rock and roll
>> I never look back
>> 
>> I'm a rocker
>> Do as I feel as I say
>> I'm a rocker
>> And no one can take that away
> 
> -- 
> 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.
> 

Peter of the Norse
rahmc...@radio1190.org



-- 
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: model form_set can not delete

2012-05-26 Thread Peter of the Norse
That's by design. The individual Modelforms don’t delete. What you can do is 
look to see if they are marked, and deleted them manually.

if formline.DELETE:
formline.instance.delete()

On May 23, 2012, at 6:01 PM, Min Hong Tan wrote:

> Hi there,
> 
> i have a problem whereby, if i for form in formset line by line and run 
> form.save().  my delete (ticked) item will not be deleted.
> and if i 'm direct using formset.save(). it did deleted. where am i code 
> wrong already?
> 
> 
> q1 = modelformset_factory(CustomerDetail,
>form= CustomerDetail lForm,
>can_delete=True)
> # bla bla bla
> 
> if request.method == 'POST':
>
> find_formsetcustomerdetail =  CustomerDetail 
> .objects.filter(customerheader__id=id_unquekey)
> formset = 
> q1(request.POST,request.FILES,queryset=find_formsetcustomerdetail)
> if formset.is_valid():
> for formline in formset: 
>  # do checking..bla bla bla
>formline.save()
> 
> Regards,
> MH
> 
> 
> 
> -- 
> 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.

Peter of the Norse
rahmc...@radio1190.org



-- 
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: TypeError Exception Value: coercing to Unicode: need string or buffer, dict found

2012-05-26 Thread Peter of the Norse
Usually when I see “TypeError Exception Value: coercing to Unicode” it means 
that some Model isn't returning the right thing in def __unicode__. Looking at 
your code, I recommend checking out the canvas returned by desenha_grafico. I 
wasn’t able to find the documentation for matplotlib, so I’m not sure which 
functions require strings.

On May 23, 2012, at 6:53 AM, Waleria wrote:

> It shows this line:
> 
> File "C:\simuladores\..\simuladores\detector\views.py" in pdf
>  259. canvas.print_pdf(response, facecolor='w', edgecolor='w')
> File "C:\Python26\Lib\site-packages\matplotlib\backend_bases.py" in
> print_pdf
>  1334. return pdf.print_pdf(*args, **kwargs)
> 
> In my code this line is: dir(canvas.print_pdf)
>canvas.print_pdf(response, facecolor='w', edgecolor='w')
> 
> but I do not know about solving.
> 
> On 23 maio, 09:37, kenneth gonsalves  wrote:
>> On Wed, 2012-05-23 at 05:16 -0700, Waleria wrote:
>>> Exception Type: TypeError Exception Value: coercing to Unicode: need
>>> string or buffer, dict found
>> 
>> you have to find out where in the code the error is coming. Then you
>> will find that you are passing a dict instead of a string.
>> --
>> regards
>> Kenneth Gonsalves
> 
> -- 
> 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.
> 

Peter of the Norse
rahmc...@radio1190.org



-- 
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: Need help

2012-05-02 Thread Peter of the Norse
There is a difference between 'localhost' and the empty string. 'localhost' 
translates into 127.0.0.1 and is sent using the internet. The empty string 
means to use local sockets for communication. At least with PostgreSQL. (It 
might be different with MySQL.) 

In short, this is not a bug. Please don't treat it as such, and learn the 
connection settings of your database.

On Apr 3, 2012, at 11:16 AM, Andre Terra wrote:

> It could be a regression bug.
> 
> To be honest, I don't see a reason why '' should become 'localhost' 
> automagically. I'd much prefer if users were forced to write 'localhost' 
> rather than having Django do it (and fail) for them.
> 
> Explicit is better than implicit.
> 
> If you haven't yet, please file a bug report: 
> https://code.djangoproject.com/newticket
> 
> 
> Cheers,
> AT
> 
> 
> On Tue, Apr 3, 2012 at 12:25 PM, thongor  wrote:
> Wow this post is really old but this also solved my problem strangely enough. 
> 
> On Thursday, June 25, 2009 2:48:32 PM UTC-4, amy wrote:
> I had this same problem...the user and pass were fine but no users 
> could authenticate on any DB, regardless of settings. 
> 
> Turns out my issue was only that I needed to add the string 
> "localhost" to the host parameter. 
> 
> It's odd since the comments specifically state to leave it blank for 
> localhost...but oh well. It worked. 
> 
> DATABASE_HOST = 'localhost' # Set to empty string for 
> localhost. Not used with sqlite3. 
> 
> Odd. 
> 
> On May 31, 6:14 am, Tim Chase  wrote: 
> > mizan rahman wrote: 
> > > No, i've checked that i've created a user named "djangouser" and the 
> > > problem still exist what will i do? Plz help me 
> > 
> > and you've checked that the password in settings.py is correct? 
> > You only confirmed one of the two problems I suggested. 
> > 
> > If both are correct, you may have to include the section of your 
> > pg_hba.conf that defines access permissions.  It usually looks 
> > something like 
> > 
> > ## 
> > local   all postgres  ident sameuser 
> > 
> > # TYPE  DATABASEUSERCIDR-ADDRESS  METHOD 
> > 
> > # "local" is for Unix domain socket connections only 
> > local   all all   ident sameuser 
> > # IPv4 local connections: 
> > hostall all 127.0.0.1/32  md5 
> > # IPv6 local connections: 
> > hostall all ::1/128   md5 
> > ## 
> > 
> > along with information about how your connecting in Django (to 
> > localhost, to the local machine by IP address, to a remote 
> > machine, etc) 
> > 
> > -tkc 
> 
> -- 
> 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/-/BI0mwz_xsrsJ.
> 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.

Peter of the Norse
rahmc...@radio1190.org



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



Using “Schemas” with MySQL

2012-03-22 Thread Peter of the Norse
In our legacy system at work, we're using different different databases on the 
same sever at the same time. It looks like ”Select * From client_a.user Inner 
Join common.table On…”. I know that ticket 6148 is still a long way from being 
included, but I was wondering if there is a workaround. I’ve seen that in 
PostgreSQL you can use db_table = 'schema\".\"tablename'
Does something similar work in MySQL? Has anyone tried it?

Peter of the Norse
rahmc...@radio1190.org



-- 
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: save() creates new entry instead of updating the passed on as instance

2012-03-12 Thread Peter of the Norse
There are some issues with the code.
First, entry.id = entry_id is redundant. It might even be the cause of the new 
Entry.
https://docs.djangoproject.com/en/dev/ref/models/instances/#how-django-knows-to-update-vs-insert
Second, the best way to update from a form and code at the same time is to do 
save(commit=False). Updating your code:
form = EntryForm(data=request.POST, instance=entry)
if form.is_valid():
  updated_entry = form.save(commit=False)
  updated_entry.owner = request.user
  updated_entry.save()
  return redirect('entry')


On Mar 10, 2012, at 7:48 PM, Zeengr wrote:

> this is my code and weirdly it creates new entry instead of updating the 
> passed one in instance argument, don't know if that because of m2m 
> relationship in Entry model or my code is broken!
> what could be the cause?
> 
> ### my edit view
> @login_required
> def edit_entry_view(request, entry_id):
> 
> try:
> entry = Entry.objects.get(pk=entry_id, is_visible=True)
> except ObjectDoesNotExist:
> return render(request, 'entry/entry.html', {'no_enties': True})
> 
> if request.method == 'POST':
> entry.owner = request.user
> entry.id = entry_id
> form = EntryForm(data=request.POST, instance=entry)
> if form.is_valid():
>   form.save()
>   return redirect('entry')
> else:
> form = EntryForm(instance=entry)
> return render(request, 'entry/edit_entry.html', {'form': form})
> 
> ###my form
> class EntryForm(ModelForm):
> 
> class Meta:
> model = Entry
> exclude = ('owner')
> 
>  
> 
> -- 
> 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/-/MQ8mh7qDPHYJ.
> 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.

Peter of the Norse
rahmc...@radio1190.org



-- 
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: Problem getting django on mac (10.5/Leopard) working

2012-02-05 Thread Peter of the Norse

On Jan 8, 2012, at 8:22 PM, larry.mart...@gmail.com wrote:

> On Jan 7, 7:13 pm, "larry.mart...@gmail.com" 
> wrote:
>> On Jan 7, 7:03 pm, David Markey  wrote:
>> 
>>> Is there a reason you didnt do easy_install django?
>> 
>> Cause I didn't know about it. I just followed the directions I found
>> at:
>> 
>> https://docs.djangoproject.com/en/dev/topics/install/
>> 
>> Is there some reason that wouldn't work?
> 
> I solved this by creating a symlink from /Library/Python/2.5/site-
> packages/django to my django install dir. Still not sure why that
> worked and putting the path in django.pth did not.

Python paths work by appending the search name to the end of everything in 
sys.path. For example, when you do `import django`, it looks for './django.py', 
'./django/__init__.py', '/usr/local/django-trunk/django.py', 
'/usr/local/django-trunk/django/__init__.py', etc. None of those paths match.

>>> On 8 January 2012 01:50, larry.mart...@gmail.com 
>>> wrote:
>> 
>>>> I am trying to get django working on my mac. I downloaded it from SVN
>>>> to /usr/local/django-trunk and it's there:
>> 
>>>> $ ls /usr/local/django-trunk/
>>>> __init__.py corehttptemplatetags bin
>>>>  db  middleware  test
>>>> confdispatchshortcuts   utils
>>>>   contrib forms
>>>> templateviews
>> 
>>>> I updated my site-packages with a django.pth file:
>> 
>>>> $ cat /Library/Python/2.5/site-packages/django.pth
>>>> /usr/local/django-trunk
>> 
>>>> python does have this dir in its path:
>> 
>>>> $ python -c "import sys; print sys.path"
>>>> ['', '/Library/Python/2.5/site-packages/cx_Oracle-5.0.2-py2.5-
>>>> macosx-10.5-i386.egg', '/System/Library/Frameworks/Python.framework/
>>>> Versions/2.5/lib/python25.zip', '/System/Library/Frameworks/
>>>> Python.framework/Versions/2.5/lib/python2.5', '/System/Library/
>>>> Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-darwin', '/
>>>> System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
>>>> plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.5/
>>>> lib/python2.5/plat-mac/lib-scriptpackages', '/System/Library/
>>>> Frameworks/Python.framework/Versions/2.5/Extras/lib/python', '/System/
>>>> Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-
>>>> tk', '/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
>>>> python2.5/lib-dynload', '/Library/Python/2.5/site-packages', '/usr/
>>>> local/django-trunk', '/System/Library/Frameworks/Python.framework/
>>>> Versions/2.5/Extras/lib/python/PyObjC']
>> 
>>>> But I still can't import it:
>> 
>>>> $ python
>>>> Python 2.5.1 (r251:54863, May  5 2011, 18:37:34)
>>>> [GCC 4.0.1 (Apple Inc. build 5465)] on darwin
>>>> Type "help", "copyright", "credits" or "license" for more information.
>>>>>>> import django
>>>> Traceback (most recent call last):
>>>>  File "", line 1, in 
>>>> ImportError: No module named django
>> 
>>>> What am I missing or doing wrong?
>> 
>>>> TIA!
>>>> -larry
>> 
>>>> --
>>>> 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.
> 

Peter of the Norse
rahmc...@radio1190.org



-- 
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: Views in django

2012-02-04 Thread Peter of the Norse
You should look into making a foreign key relationship if there actually is 
one. That way you can just annotate the the sums. Otherwise you should 
calculate the sum in the view (NOT the template) and add it to the client. 
Python allows you to add any value you want to any object.

On Feb 3, 2012, at 7:38 AM, Sandeep kaur wrote:

> On Fri, Feb 3, 2012 at 7:52 PM, Weldan  wrote:
>> Entries.objects.count()
>> 
> That will be applicable if I want to his for only 1 table's entry.
> But here I have views as :
> 
>   cd = form.cleaned_data
>name_and_address = cd['name_and_address']
>title = get_object_or_404(Variable, pk='1')
>   sign = get_object_or_404(Variable, pk='3')
>from TCC11_12.automation.choices import *
>client =
> ClientJob.objects.filter(name_and_address=name_and_address)
>amount = Amount.objects.all()
>suspence = Suspence.objects.all()
> 
> and for this I have template as :
> 
>   {% if client %}
>{% for clients in client %}
>{% for amounts in amount %}
> 
> {% if clients.job_no == amounts.job_no %}
> 
> {% if clients.name_and_address == clients.name_and_address %}
> 
>   {{ clients.receipt_no }}
>{{ clients.date }}
>{{amounts.total}}
>   {{amounts.net_total}}
>   {% endif  %}
> 
>{% endif  %}
>   
>{% endfor %}
> 
>{% endfor %}
> {% endif %}
> 
> 
> When all this is applied, it creates a view out of 2 tables i.e Amount
> and ClientJob without using foreign key. Now I want to have sum of the
> total and net_total fields for the views generated.

Peter of the Norse
rahmc...@radio1190.org



-- 
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: many-to-many queryset question

2012-01-06 Thread Peter of the Norse
One possibility is to try two excludes.

bad_authors = Authors.objects.exclude(pk__in=SetOfAuthors)
qs = Entry.objects.exclude(authors__in=bad_authors)

This will return all entries that don't have authors in SetOfAuthors. It might 
even be easier, if you can skip creating SetOfAuthors in the first place.

On Dec 6, 2011, at 12:19 PM, Felipe Morales wrote:

> could you possibly show the query generated?... 
> 
> # print qs.query
> 
> 2011/12/6 Carsten Fuchs 
> Hi all,
> 
> looking at the example models Author and Entry at 
> https://docs.djangoproject.com/en/1.3/topics/db/queries/, I would like to run 
> a query like this:
> 
>SetOfAuthors = Authors.objects.filter(...)
>qs = Entry.objects.filter(authors__in=SetOfAuthors)
> 
> such that (pseudo-code):
> 
>for e in qs:
>"e.authors is a subset of (or equal to) SetOfAuthors"
> 
> However, when I try it, the true result seems to be an intersection:
> 
>for e in qs:
>"There is (at least one) an author in e.authors that is also 
> in SetOfAuthors"
> 
> 
> How do I have to phrase the query in order to obtain only entries whose 
> authors are all in SetOfAuthors?
> 
> Best regards,
> Carsten
> 
> 
> 
> -- 
>   Cafu - the open-source Game and Graphics Engine
> for multiplayer, cross-platform, real-time 3D Action
>  Learn more at http://www.cafu.de
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 
> 
> 
> -- 
> Felipe Morales C.
> Ingenierío de Ejecución en Computación e Informática.
> 
> 
> -- 
> 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.

Peter of the Norse
rahmc...@radio1190.org



-- 
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: com_error

2011-11-25 Thread Peter of the Norse
On Nov 24, 2011, at 8:31 AM, Virginia wrote:

> I forgot to mention that Microsoft office is not install on the
> server. Is it a problem?
> 
> Regard,
> 
> V.B.

Yes. Your code is using Excel to read/write the file. Obviously that won't work 
if it's not there. http://www.python-excel.org/ says it work, but I haven't 
tried it. 

In general, I try not to use COM for anything. It hasn't been well supported 
since 2004, and there are too many "legacy design decisions". 

> On 24 nov, 09:58, Phanounou  wrote:
>> Good day everyone,
>> 
>> I am trying to create/edit and close an excel file. Everything went fine on
>> my developpement machine. But on the prod server I get the* following error*
>> :
>> 
>> com_error at /mycontracts/getContactClient/
>> (-2147221005, 'Invalid class string', None, None)
>> 
>> *and this trace back*
>> 
>>  Environment:
>> 
>> Request Method: GET
>> Request 
>> URL:http://myserveraddress/contractManager/mycontracts/getContactClient/
>> Django Version: 1.3
>> Python Version: 2.7.2
>> Installed Applications:
>> ['django.contrib.auth',
>>  'django.contrib.contenttypes',
>>  'django.contrib.sessions',
>>  'django.contrib.sites',
>>  'django.contrib.messages',
>>  'django.contrib.staticfiles',
>>  'django.contrib.admin',
>>  'mycontracts',
>>  'django.contrib.admindocs']
>> Installed Middleware:
>> ('django.middleware.common.CommonMiddleware',
>>  'django.contrib.sessions.middleware.SessionMiddleware',
>>  'django.middleware.csrf.CsrfViewMiddleware',
>>  'django.contrib.auth.middleware.AuthenticationMiddleware',
>>  'django.contrib.messages.middleware.MessageMiddleware',
>>  'django.middleware.csrf.CsrfResponseMiddleware')
>> 
>> Traceback:
>> File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in
>> get_response
>>   111. response = callback(request, *callback_args,
>> **callback_kwargs)
>> File "C:\Python27\lib\site-packages\django\contrib\auth\decorators.py" in
>> _wrapped_view
>>   23. return view_func(request, *args, **kwargs)
>> File "C:\APP\contractManager\mycontracts\views.py" in getContactClient
>>   759.   myresultForExcelFile =
>> createMatriceContactClientExcelFileNotFromRequest(clients)
>> File "C:\APP\contractManager\mycontracts\views.py" in
>> createMatriceContactClientExcelFileNotFromRequest
>>   1016.  excel   = Dispatch('Excel.Application')
>> File "C:\Python27\lib\site-packages\win32com\client\__init__.py" in Dispatch
>>   95.   dispatch, userName =
>> dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
>> File "C:\Python27\lib\site-packages\win32com\client\dynamic.py" in
>> _GetGoodDispatchAndUserName
>>   108.  return (_GetGoodDispatch(IDispatch, clsctx), userName)
>> File "C:\Python27\lib\site-packages\win32com\client\dynamic.py" in
>> _GetGoodDispatch
>>   85.IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
>> pythoncom.IID_IDispatch)
>> Exception Type: com_error at /mycontracts/getContactClient/
>> Exception Value: (-2147221005, 'Invalid class string', None, None)
>> 
>> Can you please help me see what is wrong. It's the same code on my machine
>> and on the server.
>> 
>> Regards,
>> V.B.
> 
> -- 
> 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.
> 

Peter of the Norse
rahmc...@radio1190.org



-- 
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: order by + group by

2011-09-16 Thread Peter of the Norse

On Sep 14, 2011, at 7:19 AM, Jani Tiainen wrote:

> 14.9.2011 12:46, Jonas H. kirjoitti:
>> On 09/14/2011 11:37 AM, Иван Иванов wrote:
>>> The problem here is, like Peter said, that you cannot order before
>>> grouping. And that's very annoying.
>> 
>> Of course you can, using a subselect just like I showed. SQLite example:
>> 
>> > .schema
>> CREATE TABLE a (name varchar, mod int);
>> 
>> e> select * from a;
>> b1|1
>> b1|2
>> b1|3
>> 
>> > select * from a group by name;
>> b1|3
>> 
>> > select * from (select * from a order by mod desc) group by name;
>> b1|1
>> 
> 
> Problem is that is not standard SQL.
> 
> In standard implemetation group by _requires_ aggregation function that is 
> applied to groups so you won't be able to get "last" that way.
> 
> It might work non-standard way in some implementations. And thus Django 
> usually follows standard or smallest common nominator for db backends such a 
> thing is not possible to support.

I didn’t know you could do that in SQLite. I know it doesn’t work in MySQL or 
in PostgreSQL.

The proper ANSI SQL way of doing this is “SELECT name, MIN(mod) FROM a GROUP BY 
name” and the Django way is 
“Model.objects.values('name').annotate(Min('mod'))”. But that only works on a 
table with two fields. If there is more data that you want to include, you’ll 
have to get raw. The SQL will look like “SELECT * FROM a AS t1 WHERE mod = 
(SELECT MIN(mod) FROM a AS t2 WHERE t2.name = t1.name))”. Finding out the exact 
details depends on the specifics of your queryset.

https://docs.djangoproject.com/en/1.3/topics/db/aggregation/

Peter of the Norse
rahmc...@radio1190.org



-- 
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: order by + group by

2011-09-13 Thread Peter of the Norse
What are you trying to do? The outer GROUP BY destroys the inner ORDER BY. Try 
putting them on the same level and see what happens.

On Sep 11, 2011, at 3:41 AM, Jonas H. wrote:

> Hi!
> 
> How can I express this SQL query
> 
>  SELECT ... FROM (
>SELECT ... FROM ...
>  )
> 
> in the ORM? Specifically, I want to express
> 
>  SELECT ... FROM (
>SELECT ... FROM app_model
>ORDER BY field1
>  )
>  GROUP BY field2
> 
> Is it possible without writing SQL by hand?
> 
> Thanks,
> Jonas

Peter of the Norse
rahmc...@radio1190.org



-- 
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: multiple filters on the same (reversed) foreignkey leads to multiple join

2011-09-07 Thread Peter of the Norse
That is expected behavior. The filter should be read as “there is a child with 
flag1 equals true”. Another example where this is the desired behavior would be 
Band.objects.filter(member__name='John', member__name='Paul', 
member__name='George', member__name='Ringo') . In this case you are looking for 
a band with at least four different members.

On Sep 6, 2011, at 5:09 PM, dvd wrote:

> A clean project/app in django 1.3 with just two models
> 
> from django.db import models
> 
> class Base(models.Model):
>pass
> 
> class Child(models.Model):
>base = models.ForeignKey(Base)
>flag1 = models.BooleanField()
>flag2 = models.BooleanField()
> 
> A Queryset with a single use of `.filter` works as expected:
>>>> qs = Base.objects.filter(child__flag1=True)
>>>> print qs.query
> SELECT "t0_base"."id"
> FROM "t0_base" INNER JOIN "t0_child"
>ON ("t0_base"."id" = "t0_child"."base_id")
> WHERE "t0_child"."flag1" = True
> 
> but if I start to add additional filters...
>>>> qs = qs.filter(child__flag2=True)
>>>> print qs.query
> SELECT "t0_base"."id"
> FROM "t0_base" INNER JOIN "t0_child"
>ON ("t0_base"."id" = "t0_child"."base_id")
> INNER JOIN "t0_child" T3
>ON ("t0_base"."id" = T3."base_id")
> WHERE ("t0_child"."flag1" = True  AND T3."flag2" = True )
> 
>>>> qs = qs.filter(child__flag1=False)
>>>> print qs.query
> SELECT "t0_base"."id"
> FROM "t0_base" INNER JOIN "t0_child"
>ON ("t0_base"."id" = "t0_child"."base_id")
> INNER JOIN "t0_child" T3
> ON ("t0_base"."id" = T3."base_id")
> INNER JOIN "t0_child" T4
> ON ("t0_base"."id" = T4."base_id")
> WHERE ("t0_child"."flag1" = True  AND T3."flag2" = True  AND
> T4."flag1" = False )
> 
> I don't think that this is the expected behavior, should I open a new
> bug?
> 
> david
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

Peter of the Norse
rahmc...@radio1190.org



-- 
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: problems with request.user

2008-08-28 Thread Peter of the Norse

In the docs for get_or_create()[1], it states that any argument given  
with `__` is stripped for the create() call. The reasons for this  
should be obvious. Thus, your original code was trying to save an  
empty Rating.

As for speed, the new version has less SQL. `user__pk` creates a join  
and then compares the id of the user table with the id you gave. The  
second version is the same as `user_id=request.user.id` because that’s  
how Django compares models.

[1]: 
http://docs.djangoproject.com/en/dev/ref/models/querysets/#queryset-methods-that-do-not-return-querysets

On Aug 21, 2008, at 10:43 AM, Burr Settles wrote:

>
> When the IntegrityError is thrown, the debug package stated that
> "songs_rating.user_id may not be NULL". It is indeed being thrown by
> get_or_create(). Strangely enough, request.user.id contains the
> correct value of the logged in user's ID, so I don't know what the
> problem is. I did manage to get the view working by swapping out the
> following for line 6:
>
>   rating = Rating.objects.get_or_create(user=request.user, song=song)
> [0]
>
> Now, it matches against the request.user and song objects directly, as
> opposed to their IDs as primary keys. I don't know what sort of effect
> this has on the efficiency of the underlying DB hit, but it seems the
> best I can do for now.
>
> --B
>
>
> On Aug 21, 12:20 am, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
>> On Wed, Aug 20, 2008 at 5:13 PM, Burr Settles  
>> <[EMAIL PROTECTED]> wrote:
>>
>>> I recently came back to a project I put on hold for a couple weeks,
>>> and after updating the Django trunk, all my references to
>>> "request.user.id" are broken. Here is an example view for a rating
>>> widget:
>>
>>> 1 @login_required
>>> 2 def rate(request, song_id):
>>> 3 song = get_object_or_404(Song, pk=song_id)
>>> 4 if 'rating' not in request.GET or request.GET['rating'] not in
>>> range(1,5):
>>> 5 HttpResponseRedirect(song.get_absolute_url())
>>> 6 rating =  
>>> Rating.objects.get_or_create(user__pk=request.user.id,
>>> song__pk=song.id)
>>> 7 rating.rating = int(request.GET['rating'])
>>> 8 rating.save()
>>> 9 return HttpResponseRedirect(song.get_absolute_url())
>>
>>> This throws an "IntegrityError" if the user is logged in, presumably
>>> complaining that request.user.id is NULL (at line 6).
>>
>> Presumably?  I suspect you are guessing wrong here, but it would be  
>> best to
>> make sure.  There's lots of information available on the deubg page  
>> when
>> something like an IntegrityError is thrown, have you checked the  
>> values of
>> local variables to see what request.user.id actually is?
>>
>>> But it passes
>>> the @login_required constraint just fine. I'm having similar  
>>> problems
>>> with other views that use request.user.
>>
>>> Does anyone know if the user API has recently changed? I've scoured
>>> the latest online documentation, and can't seem to find any  
>>> alternate
>>> way to access the ID of the currently logged in user. Any help is
>>> appreciated.
>>
>> I do not think anything has changed with request.user.  It seems  
>> more likely
>> something is going wrong in get_or_create.  Such as the get fails  
>> to find an
>> existing record so it tries to insert one but that is violating an  
>> integrity
>> constraint.   What, exactly, does the IntegrityError message say?   
>> Usually
>> it will give some indication of what it is objecting to, which  
>> could provide
>> a clue.
>>
>> Karen
> >

-- 
Peter of the Norse

-- 
Peter of the Norse


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: return django models using custom sql

2008-08-26 Thread Peter of the Norse

On Aug 25, 2008, at 8:12 AM, chefsmart wrote:

>
> I found a solution called djselect on this group. But is there a
> django-istic way of running custom sql queries and returning the
> results as django models?


Perhaps you are looking for the powerful but difficult `extra`  
function from http://docs.djangoproject.com/en/dev/ref/models/querysets/

Using it may cause unexpected results. Check that the SQL it generates  
is what you want, and it might not work with your model.
-- 
Peter of the Norse


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: InlineModelAdmin min_num ?

2008-08-18 Thread Peter of the Norse

Perhaps you’re thinking of `extra`?

On Aug 13, 2008, at 9:24 PM, mike wrote:

> InlineModelAdmin has max_num , shouldn't it have a min_num or am I
> missing something?
>
> Thanks,
> -Mike

-- 
Peter of the Norse


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django Setup with apache & mod_python

2008-07-03 Thread Peter of the Norse

No. It’s the Python import path. Namely what you do for “import  
path.settings” when in the Python shell. There should be a partial OS  
path in your PythonPath setting that fills in the rest.

On Jun 27, 2008, at 9:38 AM, nerdydork wrote:

> Question on apache setup using mod_python, the documentation states "…
> and replace mysite.settings with the Python import path to your Django
> project’s settings file." <-- would this be the full path to the
> settings.py file?
>
> I tried this and all I'm getting is a blank page - for every URL I
> enter

-- 
Peter of the Norse


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



  1   2   >