Newbie - Foreign Key Error

2009-01-08 Thread Tony

Dear List,

I'm developing with 1.0.2 and am getting the following error:

(1451, 'Cannot delete or update a parent row: a foreign key constraint
fails (`project/comment_comment`, CONSTRAINT
`in_reply_to_id_refs_id_35b80077` FOREIGN KEY (`in_reply_to_id`)
REFERENCES `comment_comment` (`id`))')

... where the Comment model i've defined is:

class Comment(models.Model):
  objects = CommentManager()

  user = models.ForeignKey(User)
  title = models.CharField(max_length=60)
  comment = models.TextField()
  content_type = models.ForeignKey(ContentType)
  object_id = models.PositiveIntegerField()
  owner = generic.GenericForeignKey('content_type', 'object_id')
  in_reply_to = models.ForeignKey('self', null=True, blank=True,
related_name='reply_to')
  rating = models.FloatField(default=5.00)
  created = models.DateTimeField('date created', auto_now_add=True)

... when trying to delete the owner object (genericforeignkey) and
when there are two comments pointing to the owner object - one with
in_reply_to == None, and the other with in_reply_to == the first
comment. The cascade works fine if I try to delete the first comment,
but when i'm trying to delete the owner object the error comes up???
Could anyone please help me understand why this exception is being
thrown, and how to possibly fix it?


--~--~-~--~~~---~--~~
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: Newbie - Foreign Key Error

2009-01-09 Thread Tony

I read somewhere that InnoDB cant determine the order to apply DB
operations to rows when the request spans multiple tables??? (i.e.
constraint violation???) Is anyone using MySQL + InnoDB and having
similar issues?  or is is it the norm to process models in Django on a
per model basis instead of letting the DB cascade deletes across
models?


On Jan 8, 11:17 pm, Tony  wrote:
> Dear List,
>
> I'm developing with 1.0.2 and am getting the following error:
>
> (1451, 'Cannot delete or update a parent row: a foreign key constraint
> fails (`project/comment_comment`, CONSTRAINT
> `in_reply_to_id_refs_id_35b80077` FOREIGN KEY (`in_reply_to_id`)
> REFERENCES `comment_comment` (`id`))')
>
> ... where the Comment model i've defined is:
>
> class Comment(models.Model):
>   objects = CommentManager()
>
>   user = models.ForeignKey(User)
>   title = models.CharField(max_length=60)
>   comment = models.TextField()
>   content_type = models.ForeignKey(ContentType)
>   object_id = models.PositiveIntegerField()
>   owner = generic.GenericForeignKey('content_type', 'object_id')
>   in_reply_to = models.ForeignKey('self', null=True, blank=True,
> related_name='reply_to')
>   rating = models.FloatField(default=5.00)
>   created = models.DateTimeField('date created', auto_now_add=True)
>
> ... when trying to delete the owner object (genericforeignkey) and
> when there are two comments pointing to the owner object - one with
> in_reply_to == None, and the other with in_reply_to == the first
> comment. The cascade works fine if I try to delete the first comment,
> but when i'm trying to delete the owner object the error comes up???
> Could anyone please help me understand why this exception is being
> thrown, and how to possibly fix it?
--~--~-~--~~~---~--~~
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: Newbie - Foreign Key Error

2009-01-09 Thread Tony

This is the reference: (not sure if I interpreted it right - sorry,
newb :)

"If you use a multiple-table UPDATE  statement involving InnoDB tables
for which there are foreign key constraints, the MySQL optimizer might
process tables in an order that differs from that of their parent/
child relationship. In this case, the statement fails and rolls back.
Instead, update a single table and rely on the ON UPDATE capabilities
that InnoDB provides to cause the other tables to be modified
accordingly. See Section 13.5.5.4, “FOREIGN KEY Constraints”."

from: http://dev.mysql.com/doc/refman/5.1/en/update.html
+ 
http://www.dbforums.com/mysql/1191227-cannot-delete-update-parent-row-foreign-key-constraint-fails.html


On Jan 9, 10:23 pm, Tony  wrote:
> I read somewhere that InnoDB cant determine the order to apply DB
> operations to rows when the request spans multiple tables??? (i.e.
> constraint violation???) Is anyone using MySQL + InnoDB and having
> similar issues?  or is is it the norm to process models in Django on a
> per model basis instead of letting the DB cascade deletes across
> models?
>
> On Jan 8, 11:17 pm, Tony  wrote:
>
> > Dear List,
>
> > I'm developing with 1.0.2 and am getting the following error:
>
> > (1451, 'Cannot delete or update a parent row: a foreign key constraint
> > fails (`project/comment_comment`, CONSTRAINT
> > `in_reply_to_id_refs_id_35b80077` FOREIGN KEY (`in_reply_to_id`)
> > REFERENCES `comment_comment` (`id`))')
>
> > ... where the Comment model i've defined is:
>
> > class Comment(models.Model):
> >   objects = CommentManager()
>
> >   user = models.ForeignKey(User)
> >   title = models.CharField(max_length=60)
> >   comment = models.TextField()
> >   content_type = models.ForeignKey(ContentType)
> >   object_id = models.PositiveIntegerField()
> >   owner = generic.GenericForeignKey('content_type', 'object_id')
> >   in_reply_to = models.ForeignKey('self', null=True, blank=True,
> > related_name='reply_to')
> >   rating = models.FloatField(default=5.00)
> >   created = models.DateTimeField('date created', auto_now_add=True)
>
> > ... when trying to delete the owner object (genericforeignkey) and
> > when there are two comments pointing to the owner object - one with
> > in_reply_to == None, and the other with in_reply_to == the first
> > comment. The cascade works fine if I try to delete the first comment,
> > but when i'm trying to delete the owner object the error comes up???
> > Could anyone please help me understand why this exception is being
> > thrown, and how to possibly fix it?
>
>
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



finding current url

2010-07-22 Thread Tony
Hi,
So I have many domains pointing to one url.  I am using apache in
conjunction with django.  How can I use Django to find out which
domain name is the one actually being typed in by the user?  So lets
say I have siteone.com and sitetwo.com and both go to the same website
that I will call mainsite.com/someDjangoView.  How can I find out if
the user typed in siteone.com or sitetwo.com even though they both
have the same destination?
thanks,
Tony

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



scaling my site

2010-07-23 Thread Tony
I have just about finished all the logic for my site.  In short, I
need the site to be pretty fast and a good amount of database storage
with the possibility of getting more in the future if and probably
when I need it.  Right now I am just testing my website on my computer
with Django, (mod_swgi) apache and postgresql.  I should also mention
I don't have the money right now to buy my own servers so I've been
looking into Amazon S3 and the computing cloud, EC2 but this is my
first time doing something like this so I don't know too much about
these things.  Anyway, I'm looking for advice on the best way to set
this website up and I am leaning toward using amazon's features, but I
really need a lot more insight on how all that works.  What database
server should I use?  How does S3 and EC2 work?  Should i use a web
host like web-lackey.com or something?  I'm a little unaware on how to
put something into production and how everything connects.  I accept
and appreciate any advice on the matter.
Thanks,
Tony

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



checking sessions from another domain

2010-07-27 Thread Tony
I have a few domains currently pointed to the same website.  Im only
using one of my domains to store sessions.  When I try to access a
session when someone types in a domain other then the one that I am
using sessions for, I can't because the domain name isnt the same
(obviously).  Is there any way I can access the sessions through some
sort of function without having to do a redirect to the domain that i
use to store the sessions.  I know I could store sessions for all of
the individual domains but that wont work with my experiment.  Is
there any way to access a session stored for another domain, keeping
in mind they are all pointed to the same website.
thanks for any advice,
Tony

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



importing models to script file

2010-08-04 Thread Tony
Hi, Im trying to import my models to another python file that I am
making to use the database data.  The problem is, I can't import the
models for some reason.  It keeps saying "ImportError: no module named
"  The thing is, it works on my home computer when I do it, but
when I do it on webfaction this seems to happen.  Anyone ever have a
similar problem?  And I have tried including various paths in the py
file with sys.path.append() but that hasnt worked.

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



importing models to script file

2010-08-04 Thread Tony
Hi, Im trying to import my models to another python file that I am
making to use the database data.  The problem is, I can't import the
models for some reason.  It keeps saying "ImportError: Settings cannot
be imported, because environment variable DJANGO_SETTINGS_MODULE is
undefined."
The thing is, the script works on my home computer when I do it, but
when I do it on webfaction this seems to happen.  Anyone ever have a
similar problem?  And I have tried including various paths in the py
file with sys.path.append() but that hasnt worked.  Disregard my first
message, this is actually what the error is.

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



reading pickled files

2010-08-12 Thread Tony
This is more of a python question but its in my Django project.  I am
reading a unicode object and an integer from a database into a
dictionnary and storing that in a pickled file.  Ive confirmed the
dictionary is done correctly because i print it out from the pickled
file later to check.  I also cast the unicode object as a string
before making it the key corresponding to an integer in the
dictionary.  This also appears to work.  However, when I try to use an
if statement to check if a key is in the dictionary I get this error:
"sequence item 0: expected string, int found".  Ive tried not casting
the dictionary keys as strings and I get the same error.  I dont
understand because when I print the dictionary after reading it from
the pickled file it is in string form.  I should also say that these
unicode objects Im reading in are always integer numbers.  So when i
read in from the database my end result it something like: {'200': 1,
'300': 4, etc...}.  WHat is going wrong here?

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



reading pickled files cont.

2010-08-12 Thread Tony
I just realized it said the error occurred here:
/home/opadmin/webapps/django/lib/python2.6/django/http/__init__.py in
_get_content, line 395
So I guess dJANGO has something to do with it

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



csv files

2010-08-13 Thread Tony
My script right now basically just reads from a csv file and puts it
into a dictionary for me.  However, when I make my own csv file (just
the same as any I have seen), it acts inconsistently.  For example,
sometimes it starts at the second line and another time it kept
starting at the end of the file.  This isnt after multiple reads in
one script either, just the first read from it.  my question is, has
anyone seen this before and if so how is it corrected?  Also, is there
anyway to tell the script to start from the beginning of the file?

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



Fixture? Testing? how do you do it?

2008-04-01 Thread Tony

I am relatively new to Django, and I am having trouble getting my head
around fixtures.
The Django documentation just assumes that you should  know what a
test fixture is and how to write one.  I understand that fixtures are
just test data, but how is one written?

Any guidance/examples on this would be great.

Thanks,
Tony
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



running tests.py

2008-04-02 Thread Tony

Hi,

It might just be me not seeing the obvious but I'm sure in the django
documentation it says that if you type the command "python manage.py
test" it will "Looking for unit tests and doctests in the models.py
and tests.py files in each installed application" and run those tests?
Or am I totally wrong?

I have written doctests in models.py and they run fine when I run the
command, but my test.py files doesn't run at all. Have I missed
anything?
I don't have to add a TEST_RUNNER do i?

Here is what I have in my test.py file
"""
 from django.test import TestCase

class UserAuthorisationTest(TestCase):
def unauthorised_user(self):
response = self.client.get('/lib/')
self.failUnlessEqual(response.status_code, 302)
"""
It looks ok to me, but am I missing something critical?

Any help will be greatly received.

Thanks in advance,
Tony
--~--~-~--~~~---~--~~
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: Fixture? Testing? how do you do it?

2008-04-02 Thread Tony

Ah, that makes it alot clearer.

I've had a go at it but I can't seem to get it to run my test.py file.
Any reason why that might be?

Thanks for your help.

On Apr 1, 6:17 pm, Prairie Dogg <[EMAIL PROTECTED]> wrote:
> I just did this for the first time last night, although I definitely
> don't
> know how to write good tests, at least I wrote some tests.
>
> First thing you'll wanna check out if you haven't is:
>
> http://www.djangoproject.com/documentation/testing/
>
> But I assume you have, so I'll just get on to the fixtures.
>
> Probably the easiest way to create a fixture is to enter some data
> into your site from the admin interface.  Then go to your project
> folder (the one with manage.py in it) and type something like:
>
> $>python manage.py dumpdata --indent=4 --format=json >
> my_text_fixture.json
>
> Both the --indent and --format flags are optional, I think the output
> is JSON by default.  For more information on dumping data into a
> fixture, check out:
>
> http://www.djangoproject.com/documentation/django-admin/#dumpdata-app...
>
> Then, when you write your unit tests for your app in tests.py, you
> simply load up that fixture at the beginning of each test case.  The
> docs say that the test database is flushed and restored for each
> individual test case.  Here's what one of my test cases looks like:
>
> class FormatTestCase(TestCase):
> fixtures = ['book/test_data/book_test_data.json']
>
> def setUp(self):
> self.haiku = Submission.objects.get(title="A Peaceful Haiku")
>
> def testPermalink(self):
> self.assertEquals(self.haiku.get_absolute_url(), "/submission/
> peaceful-haiku/")
>
> Hope that helps.  Obviously, this only works for unit tests.  I'm not
> entirely sure how you load fixtures for doctests, maybe someone more
> experienced would like to tackle that.
>
> On Apr 1, 12:31 pm, Tony <[EMAIL PROTECTED]> wrote:
>
> > I am relatively new to Django, and I am having trouble getting my head
> > around fixtures.
> > The Django documentation just assumes that you should  know what a
> > test fixture is and how to write one.  I understand that fixtures are
> > just test data, but how is one written?
>
> > Any guidance/examples on this would be great.
>
> > Thanks,
> > Tony
--~--~-~--~~~---~--~~
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: running tests.py

2008-04-02 Thread Tony

Ah I see, "tests.py" rather than "test.py"

Its an annoying detail that a newbie like me would miss.

Thanks.

On Apr 2, 10:35 pm, "Russell Keith-Magee" <[EMAIL PROTECTED]>
wrote:
> On 4/3/08, Tony <[EMAIL PROTECTED]> wrote:
>
>
>
> >  Hi,
>
> >  It might just be me not seeing the obvious but I'm sure in the django
> >  documentation it says that if you type the command "python manage.py
> >  test" it will "Looking for unit tests and doctests in the models.py
> >  and tests.py files in each installed application" and run those tests?
> >  Or am I totally wrong?
>
> Correct.
>
> >  I have written doctests in models.py and they run fine when I run the
> >  command, but my test.py files doesn't run at all. Have I missed
> >  anything?
>
> Yes. The file needs to be called "tests.py", not "test.py". :-)
>
> For the record (although it sounds like you're doing this), the
> tests.py module needs to be in the application module - i.e., in the
> same directory as models.py
>
> Yours,
> Russ Magee %-)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



TestCase: Client Login always false

2008-04-03 Thread Tony

Hi

I have tried numerous ways to login through client() but it keeps
returning false.
I have tested it in the shell and it works fine and returns
login=true.
But in my tests.py file, it keeps failing the test because it keeps
returning login=false.

Here is my script:
"""
from django.test import TestCase
from django.test.client import Client

class AuthorisedUserTests(TestCase):
def setUp(self):
self.client = Client()

def test_login_returns_True(self):
response = self.client.login(username='auser', 
password='apassword')
self.failUnlessEqual(response, True)
"""

I have used Djangos inbuilt user authorisation through the use of
"from django.contrib.auth.models import User".  I am also using
decorators.

Where am I going wrong?

Thanks in advance,
Tony
--~--~-~--~~~---~--~~
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: TestCase: Client Login always false

2008-04-03 Thread Tony

Ah sweet, thanks DR.

It doesn't tell you that in the documentation, but I guess thats the
reason for loading fixtures.

On 3 Apr, 10:19, Daniel Roseman <[EMAIL PROTECTED]> wrote:
> Tony wrote:
> > Hi
>
> > I have tried numerous ways to login through client() but it keeps
> > returning false.
> > I have tested it in the shell and it works fine and returns
> > login=true.
> > But in my tests.py file, it keeps failing the test because it keeps
> > returning login=false.
>
> > Here is my script:
> > """
> > from django.test import TestCase
> > from django.test.client import Client
>
> > class AuthorisedUserTests(TestCase):
> >def setUp(self):
> >self.client = Client()
>
> >def test_login_returns_True(self):
> >response = self.client.login(username='auser', 
> > password='apassword')
> >self.failUnlessEqual(response, True)
> > """
>
> > I have used Djangos inbuilt user authorisation through the use of
> > "from django.contrib.auth.models import User".  I am also using
> > decorators.
>
> > Where am I going wrong?
>
> > Thanks in advance,
> > Tony
>
> The test runner always creates a new blank database to run against, so
> there are no users set up. You will need to create one first:
>
> from django.contrib.auth.models import User
> testuser = User.objects.create_user('auser', '[EMAIL PROTECTED]',
> 'apassword')
> testuser.is_staff=True
> testuser.save()
>
> You could probably do this in the setUp method if you are going to be
> using it in multiple tests.
> --
> DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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
-~--~~~~--~~--~--~---



TestCase: template.name AttributeError

2008-04-03 Thread Tony

I keep getting an AttributeError then I specify
"self.assertEqual(response.template.name, 'index.html')"
I keep getting...
AttributeError: 'list' object has no attribute 'name'

Is there something I have missed in the setup?

Thanks in advance for any help,
Tony
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



TestCase: problem with returning posted data, it returns excepted data instead

2008-04-06 Thread Tony

I am testing my view using the Client(), and I am having trouble
retrieving a variable that is in a try and except block.  It is not
returning the posted item in the block, but instead always returning
the excepted data.

Here is the snippet I am trying to test in my view.py:
"""
allchecks = Checks.objects.all()
datagroups = []
for i in allchecks:
i.datagroup
if not i.datagroup in datagroups:
datagroups += ['%s' % i.datagroup]

try:
data = request.POST['datagroup']
except:
data=""

if data:
checkslist = Checks.objects.filter(datagroup=data)
else:
checkslist = []
"""

In my rendered template I have a filter input box which contains
everything stored in datagroups.  What I doing here is posting the
selected filter in datagroups to display the results from my Checks
table.

This all works fine in practice but when I am testing it using
Django's Client(), it never returns data as the posted datagroup but
rather returns the excepted data="".

This is what I have in my test.py:
"""
class checksearchTests(TestCase):
fixtures = ['testdata/my_text_fixture.json']

def setUp(self):
self.client = Client()
#login user to perform following tests
self.client.login(username='auser', password='apassword')

response = self.client.get('/lib/project/7/checksearch/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.template[0].name, 'allsearch.html')
self.failUnless('testtrial1' in response.content)

def test_post_datagroup_search_ALC(self):
dg='ALC'
post_data = {'data': dg}
postresponse = self.client.post('/lib/project/7/checksearch/',
post_data)

response = self.client.get('/lib/project/7/checksearch/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.template[0].name, 'allsearch.html')
self.failUnless('Results for datagroup: ALC' in 
response.content)
"""

Its failing on "self.failUnless('Results for datagroup: ALC' in
response.content)" because the posted data has not been rendered, so
instead its rendering dg="".

Anyidea why this is? Is it the way I have written my function?


Any help is received with thanks.
Tony.
--~--~-~--~~~---~--~~
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: Testing Search form processing

2008-04-07 Thread Tony

Ah I know where I have gone wrong now. I should have specified q
instead of query in my test function.
Its so obvious now. I think I spent too long looking at  test
function, it made my eyes blurry.

Thanks
Tony

On Apr 7, 10:47 am, Tony <[EMAIL PROTECTED]> wrote:
> I have developed an application using the search form from chapter 7
> of the Django Book,http://www.djangobook.com/en/1.0/chapter07/. I am
> having trouble testing the search view, it seems like (from my view
> below) it is not returning 'q', but rather, returning nothing.  It
> might be the way I have written my test function but I'm not sure
> where I am going wrong.
>
> This is my test function:
> """
> def test_get_keyword_search_aevnam1a(self):
> #posting a keyword search for 'aevnam1a'
> kw='aevnam1a'
> get_data = {'query': kw}
> response = self.client.get('/lib/project/7/checksearch/', get_data)
>
> #checking that the search prodced results
> self.assertEqual(response.status_code, 200)
> self.assertEqual(response.template[0].name, 'allsearch.html')
> self.failUnless('Results for keyword search: aevnam1a' in
> response.content)
> """
>
> This is my view:
> """
> def checksearch(request, project_id):
> 
> 
> query = request.GET.get('q', '')
>
> if query:
> qset = (
> Q(variable__icontains=query) |
> Q(checkname__icontains=query) |
> Q(errmsg__icontains=query)
> )
> results = Checks.objects.filter(qset).distinct()
> else:
> results = []
> return render_to_response("allsearch.html", {
> 'results': results,
> 'query': query,
> })
> """
>
> Thank you in advance for any help.
> Tony
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Testing Search form processing

2008-04-07 Thread Tony


I have developed an application using the search form from chapter 7
of the Django Book, http://www.djangobook.com/en/1.0/chapter07/. I am
having trouble testing the search view, it seems like (from my view
below) it is not returning 'q', but rather, returning nothing.  It
might be the way I have written my test function but I'm not sure
where I am going wrong.

This is my test function:
"""
def test_get_keyword_search_aevnam1a(self):
#posting a keyword search for 'aevnam1a'
kw='aevnam1a'
get_data = {'query': kw}
response = self.client.get('/lib/project/7/checksearch/', get_data)

#checking that the search prodced results
self.assertEqual(response.status_code, 200)
self.assertEqual(response.template[0].name, 'allsearch.html')
self.failUnless('Results for keyword search: aevnam1a' in
response.content)
"""

This is my view:
"""
def checksearch(request, project_id):


query = request.GET.get('q', '')

if query:
qset = (
Q(variable__icontains=query) |
Q(checkname__icontains=query) |
Q(errmsg__icontains=query)
)
results = Checks.objects.filter(qset).distinct()
else:
results = []
return render_to_response("allsearch.html", {
'results': results,
'query': query,
})
"""

Thank you in advance for any help.
Tony

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



Testing dynamic post data

2008-04-07 Thread Tony

I am still a newbie with Django but I am well on my way to completing
my first Django application, but not yet as I am having some trouble
testing and any help would be greatly recieved.

I am having trouble testing some POST data.  What I am trying to do in
my view is post some dynamic data and then save that to the database.
It all works fine in practice but then I test it I get an error
saying, "OperationalError: no such column: selectedcheck6".  I'm not
sure why this is or what it means.

I have added my test function below, I think what I have done is right
but obviously not as I'm getting that error.  My view is also below as
well to provide clarity.

test function
"""
class selectedTests(TestCase):
fixtures = ['testdata/my_text_fixture.json']

def setUp(self):
self.client = Client()

def test_add_check_to_testtrial1(self):
#adding check_id=6 to this trial
i=6
post_data = {'selectedcheck%s' %i : 'selectedcheck%s' %i}
response = self.client.post('/lib/project/7/', post_data)

#checking that check has been added to the trial
self.assertEqual(response.status_code, 200)
self.assertEqual(response.template[0].name, 'selected.html')
self.failUnless('You do not currently have any checks selected 
for
this study.' not in response.content)
"""

View
"""
def selected(request, project_id):
..

if request.method == 'POST':
selected1 = Project.objects.get(id=project_id)

ids = ''
for i in range (1,100):
data = request.POST.get('selectedcheck%s' %i, '')
ids += '%s,' % (data)

list2 = Checks.objects.extra(where=['id IN (%s)' % ids])
for i in list2:
range2 = request.POST.get('range%s' %i.id, 'None')
comments = request.POST.get('comment%s' %i.id, 'None')
if range2 == 'None':
range2 = ''
if comments == 'None':
comments = ''
list3 = Checks.objects.get(id=i.id)
new = StudyChecksFinal(projectid=selected1, 
checkid=list3,
checkrange='%s' % range2, comments='%s' % comments)
new.save()

#matches projectid to project.id and filters checks for that project
qset = (Q(projectid = project_id))
results = StudyChecksFinal.objects.filter(qset)
return render_to_response('selected.html', {
'results': results,
'currentproject': currentproject,
'theuser' : theuser,
})
"""

Many thanks in advance
Tony
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Django and LDAP

2012-09-10 Thread Tony
Hi everybody,

I am new to Django and Python, and right now, i am going through the 
documentation. I have an assignment at my Faculty, where i need to install 
Django, 389ds LDAP server (where i have to store my users) and i need to 
somehow connect them two, so i can auth users from LDAP when logging into 
Django. i have read some documentation, and i saw a massive lines of code, 
add this, add that, and i don't get any of that.

Can someone please help me with this issue, i'll be very grateful.

Thank you

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



Module or plugin architecture

2011-10-01 Thread Tony
Hello,

I am new to Django and I have a question about module or plugin
architecture.
Is it possible to write a module with Django and add it to a current
Django application.

Thank you very much.
Regards,
Tony

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



manytomany query problem

2011-06-22 Thread Tony
I have two models with a manytomany through relation (A and B).  B has
a self referential manytomany relation (a userprofile model).  How
could I filter objects of model B per each relationship with model A?
So lets say 3 arbitrary model A objects have 20 model B object
relations each.  I want to filter the relations so when I return the
filtered version of model A is outputted, each object of type model A
returns only object Bs (the userprofiles) that are connected through
the self referential manytomany relationship to the userprofile (the
object B, sorry if I use them interchangeably but they are the same
thing) that is currently sending in the request.  I figure out which
userprofile is sending the request with a unique identifier sent by
the user in the request (basically their primary key).  Is this type
of filtering possible.

-- 
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: manytomany query problem

2011-06-23 Thread Tony
You have the question I was asking correct, your notation was fine.
The only thing I should add is I want to return all A, but filter  my
"B1"s (as you put it) for each A. I will post my models if need be,
but they are on another computer and its not convenient right now.  In
the meantime, do you have any ideas for this query?

On Jun 23, 11:50 am, Nikhil Somaru  wrote:
> It is very hard to read your message. Please format it appropriately next
> time. Avoid repeating variable names and mixing classes with instances.
> Could you post your models here?
>
> Are you defining the following structure:
>
> A hasMany B;
> B hasMany A;
> B hasMany B;
>
> So you want* A such that A.yourB1.yourB2 exists*? Sorry for the notation.
>
>
>
> On Thu, Jun 23, 2011 at 12:03 PM, Tony  wrote:
> > I have two models with a manytomany through relation (A and B).  B has
> > a self referential manytomany relation (a userprofile model).  How
> > could I filter objects of model B per each relationship with model A?
> > So lets say 3 arbitrary model A objects have 20 model B object
> > relations each.  I want to filter the relations so when I return the
> > filtered version of model A is outputted, each object of type model A
> > returns only object Bs (the userprofiles) that are connected through
> > the self referential manytomany relationship to the userprofile (the
> > object B, sorry if I use them interchangeably but they are the same
> > thing) that is currently sending in the request.  I figure out which
> > userprofile is sending the request with a unique identifier sent by
> > the user in the request (basically their primary key).  Is this type
> > of filtering possible.
>
> > --
> > 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.
>
> --
> Yours,
> Nikhil Somaru

-- 
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: manytomany query problem

2011-06-23 Thread Tony
Nikhil,
This email will be significantly shorter than the one I wrote 5
minutes ago before my laptop ran out of battery and failed to get
sent.  I didn't explain this clearly so I am going to give an example
(a much smaller one than the one I jsut wrote).
Lets say I have 3 object As (a1, a2, a3) and 3 object Bs (b1, b2, b3).
the relations are as follows:
a1 to (b1, b2), a2 to (b2, b3), a3 to (b1, b3)
The user who makes the request is b2. b2 has a "friend connection"
with b1 only (so b2 to (b1,)).  It could have more friends, but for
simplicity it will have only 1.  What I want to return is this:
a1 to (b1,), a2 to None, a3 to (b1,).

I always want to return all of my model "A" objects, but I want to
filter the model "B" objects within each based on who the current
user's "friend connections are".  How do I do this in code?

On Jun 23, 9:02 pm, Nikhil Somaru  wrote:
> Hi Tony,
>
> Try this:
>
> q1 = A.objects.filter(B=your_b1_instance) # that gets you all A with B =
> your_b1_instance
> q2 = A.objects.filter(B__B=your_b2_instance) #that gets you all A with B.B =
> your_b2_instance
> result = set(q1).intersection(set(q2)) #gives you the A's that are common to
> both sets.
> result = list(result) #convert it back to a list
>
> There might be an easier way to do it with just the ORM, but that should
> work for now
>
>
>
>
>
>
>
>
>
> On Thu, Jun 23, 2011 at 8:46 PM, Tony  wrote:
> > You have the question I was asking correct, your notation was fine.
> > The only thing I should add is I want to return all A, but filter  my
> > "B1"s (as you put it) for each A. I will post my models if need be,
> > but they are on another computer and its not convenient right now.  In
> > the meantime, do you have any ideas for this query?
>
> > On Jun 23, 11:50 am, Nikhil Somaru  wrote:
> > > It is very hard to read your message. Please format it appropriately next
> > > time. Avoid repeating variable names and mixing classes with instances.
> > > Could you post your models here?
>
> > > Are you defining the following structure:
>
> > > A hasMany B;
> > > B hasMany A;
> > > B hasMany B;
>
> > > So you want* A such that A.yourB1.yourB2 exists*? Sorry for the notation.
>
> > > On Thu, Jun 23, 2011 at 12:03 PM, Tony  wrote:
> > > > I have two models with a manytomany through relation (A and B).  B has
> > > > a self referential manytomany relation (a userprofile model).  How
> > > > could I filter objects of model B per each relationship with model A?
> > > > So lets say 3 arbitrary model A objects have 20 model B object
> > > > relations each.  I want to filter the relations so when I return the
> > > > filtered version of model A is outputted, each object of type model A
> > > > returns only object Bs (the userprofiles) that are connected through
> > > > the self referential manytomany relationship to the userprofile (the
> > > > object B, sorry if I use them interchangeably but they are the same
> > > > thing) that is currently sending in the request.  I figure out which
> > > > userprofile is sending the request with a unique identifier sent by
> > > > the user in the request (basically their primary key).  Is this type
> > > > of filtering possible.
>
> > > > --
> > > > 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.
>
> > > --
> > > Yours,
> > > Nikhil Somaru
>
> > --
> > 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.
>
> --
> Yours,
> Nikhil Somaru

-- 
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: manytomany query problem

2011-06-26 Thread Tony
It means I want some objects of type B to be filtered within their
parent relation of model A.  I am about to try Alex's suggestion, but
any other suggestions would be great too and I will let you guys know
if it works.

On Jun 24, 3:36 pm, Nikhil Somaru  wrote:
> When you say 'filter' do you mean that you want some objects removed (i.e.
> filtered), or, do you mean that you want all the A's returned to be in a
> list that is sorted?
>
>
>
>
>
>
>
>
>
> On Fri, Jun 24, 2011 at 5:55 AM, Tony  wrote:
> > Nikhil,
> > This email will be significantly shorter than the one I wrote 5
> > minutes ago before my laptop ran out of battery and failed to get
> > sent.  I didn't explain this clearly so I am going to give an example
> > (a much smaller one than the one I jsut wrote).
> > Lets say I have 3 object As (a1, a2, a3) and 3 object Bs (b1, b2, b3).
> > the relations are as follows:
> > a1 to (b1, b2), a2 to (b2, b3), a3 to (b1, b3)
> > The user who makes the request is b2. b2 has a "friend connection"
> > with b1 only (so b2 to (b1,)).  It could have more friends, but for
> > simplicity it will have only 1.  What I want to return is this:
> > a1 to (b1,), a2 to None, a3 to (b1,).
>
> > I always want to return all of my model "A" objects, but I want to
> > filter the model "B" objects within each based on who the current
> > user's "friend connections are".  How do I do this in code?
>
> > On Jun 23, 9:02 pm, Nikhil Somaru  wrote:
> > > Hi Tony,
>
> > > Try this:
>
> > > q1 = A.objects.filter(B=your_b1_instance) # that gets you all A with B =
> > > your_b1_instance
> > > q2 = A.objects.filter(B__B=your_b2_instance) #that gets you all A with
> > B.B =
> > > your_b2_instance
> > > result = set(q1).intersection(set(q2)) #gives you the A's that are common
> > to
> > > both sets.
> > > result = list(result) #convert it back to a list
>
> > > There might be an easier way to do it with just the ORM, but that should
> > > work for now
>
> > > On Thu, Jun 23, 2011 at 8:46 PM, Tony  wrote:
> > > > You have the question I was asking correct, your notation was fine.
> > > > The only thing I should add is I want to return all A, but filter  my
> > > > "B1"s (as you put it) for each A. I will post my models if need be,
> > > > but they are on another computer and its not convenient right now.  In
> > > > the meantime, do you have any ideas for this query?
>
> > > > On Jun 23, 11:50 am, Nikhil Somaru  wrote:
> > > > > It is very hard to read your message. Please format it appropriately
> > next
> > > > > time. Avoid repeating variable names and mixing classes with
> > instances.
> > > > > Could you post your models here?
>
> > > > > Are you defining the following structure:
>
> > > > > A hasMany B;
> > > > > B hasMany A;
> > > > > B hasMany B;
>
> > > > > So you want* A such that A.yourB1.yourB2 exists*? Sorry for the
> > notation.
>
> > > > > On Thu, Jun 23, 2011 at 12:03 PM, Tony  wrote:
> > > > > > I have two models with a manytomany through relation (A and B).  B
> > has
> > > > > > a self referential manytomany relation (a userprofile model).  How
> > > > > > could I filter objects of model B per each relationship with model
> > A?
> > > > > > So lets say 3 arbitrary model A objects have 20 model B object
> > > > > > relations each.  I want to filter the relations so when I return
> > the
> > > > > > filtered version of model A is outputted, each object of type model
> > A
> > > > > > returns only object Bs (the userprofiles) that are connected
> > through
> > > > > > the self referential manytomany relationship to the userprofile
> > (the
> > > > > > object B, sorry if I use them interchangeably but they are the same
> > > > > > thing) that is currently sending in the request.  I figure out
> > which
> > > > > > userprofile is sending the request with a unique identifier sent by
> > > > > > the user in the request (basically their primary key).  Is this
> > type
> > > > > > of filtering possible.
>
> > > > > > --
> > > > > > You received this message because you are subscribed to the Google
> > > > Groups

Re: manytomany query problem

2011-06-26 Thread Tony
Alex,
I did it your way and although it does return the intersected sets
correctly, it is not exactly what I want because I need those sets to
be returned with their respective model A objects.  So, referring back
to the end result of my example above:
a1 to (b1,), a2 to None, a3 to (b1,)
I want to return this (I use the prime symbol ' to denote that these
are the new filtered sets):
a1'.b_set = (b1,) a2'.b_set = None, a3.b_set = (b1,)
You gave me this:
[(b1,), None (or does it return nothing?), (b1,)]
You were close, but how to I switch yours to what I want above it?

On Jun 24, 3:36 pm, Nikhil Somaru  wrote:
> When you say 'filter' do you mean that you want some objects removed (i.e.
> filtered), or, do you mean that you want all the A's returned to be in a
> list that is sorted?
>
>
>
>
>
>
>
>
>
> On Fri, Jun 24, 2011 at 5:55 AM, Tony  wrote:
> > Nikhil,
> > This email will be significantly shorter than the one I wrote 5
> > minutes ago before my laptop ran out of battery and failed to get
> > sent.  I didn't explain this clearly so I am going to give an example
> > (a much smaller one than the one I jsut wrote).
> > Lets say I have 3 object As (a1, a2, a3) and 3 object Bs (b1, b2, b3).
> > the relations are as follows:
> > a1 to (b1, b2), a2 to (b2, b3), a3 to (b1, b3)
> > The user who makes the request is b2. b2 has a "friend connection"
> > with b1 only (so b2 to (b1,)).  It could have more friends, but for
> > simplicity it will have only 1.  What I want to return is this:
> > a1 to (b1,), a2 to None, a3 to (b1,).
>
> > I always want to return all of my model "A" objects, but I want to
> > filter the model "B" objects within each based on who the current
> > user's "friend connections are".  How do I do this in code?
>
> > On Jun 23, 9:02 pm, Nikhil Somaru  wrote:
> > > Hi Tony,
>
> > > Try this:
>
> > > q1 = A.objects.filter(B=your_b1_instance) # that gets you all A with B =
> > > your_b1_instance
> > > q2 = A.objects.filter(B__B=your_b2_instance) #that gets you all A with
> > B.B =
> > > your_b2_instance
> > > result = set(q1).intersection(set(q2)) #gives you the A's that are common
> > to
> > > both sets.
> > > result = list(result) #convert it back to a list
>
> > > There might be an easier way to do it with just the ORM, but that should
> > > work for now
>
> > > On Thu, Jun 23, 2011 at 8:46 PM, Tony  wrote:
> > > > You have the question I was asking correct, your notation was fine.
> > > > The only thing I should add is I want to return all A, but filter  my
> > > > "B1"s (as you put it) for each A. I will post my models if need be,
> > > > but they are on another computer and its not convenient right now.  In
> > > > the meantime, do you have any ideas for this query?
>
> > > > On Jun 23, 11:50 am, Nikhil Somaru  wrote:
> > > > > It is very hard to read your message. Please format it appropriately
> > next
> > > > > time. Avoid repeating variable names and mixing classes with
> > instances.
> > > > > Could you post your models here?
>
> > > > > Are you defining the following structure:
>
> > > > > A hasMany B;
> > > > > B hasMany A;
> > > > > B hasMany B;
>
> > > > > So you want* A such that A.yourB1.yourB2 exists*? Sorry for the
> > notation.
>
> > > > > On Thu, Jun 23, 2011 at 12:03 PM, Tony  wrote:
> > > > > > I have two models with a manytomany through relation (A and B).  B
> > has
> > > > > > a self referential manytomany relation (a userprofile model).  How
> > > > > > could I filter objects of model B per each relationship with model
> > A?
> > > > > > So lets say 3 arbitrary model A objects have 20 model B object
> > > > > > relations each.  I want to filter the relations so when I return
> > the
> > > > > > filtered version of model A is outputted, each object of type model
> > A
> > > > > > returns only object Bs (the userprofiles) that are connected
> > through
> > > > > > the self referential manytomany relationship to the userprofile
> > (the
> > > > > > object B, sorry if I use them interchangeably but they are the same
> > > > > > thing) that is currently sending in the request.  I figure out
> > which
> > > > > > userprofile is sending t

Re: manytomany query problem

2011-07-18 Thread Tony
As I still haven't solved this, any suggestions would be appreciated.

On Jun 26, 10:16 pm, Tony  wrote:
> Alex,
> I did it your way and although it does return the intersected sets
> correctly, it is not exactly what I want because I need those sets to
> be returned with their respective model A objects.  So, referring back
> to the end result of my example above:
> a1 to (b1,), a2 to None, a3 to (b1,)
> I want to return this (I use the prime symbol ' to denote that these
> are the new filtered sets):
> a1'.b_set = (b1,) a2'.b_set = None, a3.b_set = (b1,)
> You gave me this:
> [(b1,), None (or does it return nothing?), (b1,)]
> You were close, but how to I switch yours to what I want above it?
>
> On Jun 24, 3:36 pm, Nikhil Somaru  wrote:
>
> > When you say 'filter' do you mean that you want some objects removed (i.e.
> > filtered), or, do you mean that you want all the A's returned to be in a
> > list that is sorted?
>
> > On Fri, Jun 24, 2011 at 5:55 AM, Tony  wrote:
> > > Nikhil,
> > > This email will be significantly shorter than the one I wrote 5
> > > minutes ago before my laptop ran out of battery and failed to get
> > > sent.  I didn't explain this clearly so I am going to give an example
> > > (a much smaller one than the one I jsut wrote).
> > > Lets say I have 3 object As (a1, a2, a3) and 3 object Bs (b1, b2, b3).
> > > the relations are as follows:
> > > a1 to (b1, b2), a2 to (b2, b3), a3 to (b1, b3)
> > > The user who makes the request is b2. b2 has a "friend connection"
> > > with b1 only (so b2 to (b1,)).  It could have more friends, but for
> > > simplicity it will have only 1.  What I want to return is this:
> > > a1 to (b1,), a2 to None, a3 to (b1,).
>
> > > I always want to return all of my model "A" objects, but I want to
> > > filter the model "B" objects within each based on who the current
> > > user's "friend connections are".  How do I do this in code?
>
> > > On Jun 23, 9:02 pm, Nikhil Somaru  wrote:
> > > > Hi Tony,
>
> > > > Try this:
>
> > > > q1 = A.objects.filter(B=your_b1_instance) # that gets you all A with B =
> > > > your_b1_instance
> > > > q2 = A.objects.filter(B__B=your_b2_instance) #that gets you all A with
> > > B.B =
> > > > your_b2_instance
> > > > result = set(q1).intersection(set(q2)) #gives you the A's that are 
> > > > common
> > > to
> > > > both sets.
> > > > result = list(result) #convert it back to a list
>
> > > > There might be an easier way to do it with just the ORM, but that should
> > > > work for now
>
> > > > On Thu, Jun 23, 2011 at 8:46 PM, Tony  wrote:
> > > > > You have the question I was asking correct, your notation was fine.
> > > > > The only thing I should add is I want to return all A, but filter  my
> > > > > "B1"s (as you put it) for each A. I will post my models if need be,
> > > > > but they are on another computer and its not convenient right now.  In
> > > > > the meantime, do you have any ideas for this query?
>
> > > > > On Jun 23, 11:50 am, Nikhil Somaru  wrote:
> > > > > > It is very hard to read your message. Please format it appropriately
> > > next
> > > > > > time. Avoid repeating variable names and mixing classes with
> > > instances.
> > > > > > Could you post your models here?
>
> > > > > > Are you defining the following structure:
>
> > > > > > A hasMany B;
> > > > > > B hasMany A;
> > > > > > B hasMany B;
>
> > > > > > So you want* A such that A.yourB1.yourB2 exists*? Sorry for the
> > > notation.
>
> > > > > > On Thu, Jun 23, 2011 at 12:03 PM, Tony  wrote:
> > > > > > > I have two models with a manytomany through relation (A and B).  B
> > > has
> > > > > > > a self referential manytomany relation (a userprofile model).  How
> > > > > > > could I filter objects of model B per each relationship with model
> > > A?
> > > > > > > So lets say 3 arbitrary model A objects have 20 model B object
> > > > > > > relations each.  I want to filter the relations so when I return
> > > the
> > > > > > > filtered version of model A is outputted, each object of type 
> > > &g

list created from a table in my database

2011-01-12 Thread Tony
Hi all,
I want to create a page on my site where I can extract the rows from a
table in my database and allow certain users with the proper access to
be able to add, delete, and change the columns of the rows if they
want.  I think I have the multi-user thing pretty much figured out
(although I dont know if Im doing the best way, Ive just made
customuser model and then used inheritance for the other models that
represent users), but my main question is, what would be the best way
to go about displaing the rows to be edited, deleted, etc.. to a page
on my website.  I know I could display them if I just do queries like
modelname.object.filter(...) but the editing part and all that is
still sort of up in the air.  I appreciate any input on the matter.
thanks,
Tony

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



custom admin

2011-01-12 Thread Tony
Is there any way to make a custom admin for a site but use parts of
the existing admin.  It has a lot of good features but there are
certaint hings I dont want revealed and yes i know I can limit access,
but what if I want to limit lets say, a teacher to only his/her
student's information, or i want to change the look of the site.

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



jquery problem

2011-01-16 Thread Tony
I am using a jquery project for forms that someone else created to
give myself a jump start on what Im trying to do.  Unfortunately, I
can't get any other plugins to work that I download.  No other jquery
plugins seem to work and Im pretty sure I have the directory paths
right and everything.  I have gotten simple jquery commands to work so
I know some things must work.  Why am I getting this problem?  Also I
have gotten these plugins to work outside of django.  To reiterate,
I've staerted with someone elses project and their jquery file.  It
works.  Then I try to add other plugins and none will work.

-- 
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: jquery problem

2011-01-17 Thread Tony
I did what you've recommended, I put in the jquery.js file that I used
while testing outside of django.  There was still no success.  Thus
far I cant get any other plugin to work beside the one it dynamic
formset one I started with.  I even deleted that file temporarily to
see if it was "blocking" the other files somehow.  It didn't work.
Are there any other suggestions on how to get these jquery files to
work in my django project?

On Jan 17, 10:14 am, sureronald  wrote:
> Confirm the plugin's jquery version requirement. Maybe the plugin
> requires another jquery version
>
> On Jan 17, 8:48 am, Tony Lambropoulos  wrote:
>
> > Prashanth,
> > This has to do with django because they work outside of django.
>
> > On Mon, Jan 17, 2011 at 6:12 AM, Prashanth  wrote:
> > > Hi Tony,
>
> > > On Mon, Jan 17, 2011 at 8:57 AM, Tony  wrote:
>
> > >>  Unfortunately, I can't get any other plugins to work that I download.  
> > >> No
> > >> other jquery
> > >> plugins seem to work and Im pretty sure I have the directory paths
> > >> right and everything.
>
> > > Very lame, How would someone know why something dint work?
>
> > >> Then I try to add other plugins and none will work.
>
> > > How is this related to Django? Hit Jquery mailing list.
>
> > > --
> > > regards,
> > > Prashanth
> > > twitter: munichlinux
> > > blog: honeycode.in
> > > irc: munichlinux, JSLint, munichpython.
>
> > > --
> > > 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.



variable column name

2011-02-02 Thread Tony
If I return a string variable from a template to a view function, and
the string variable is the name of a model (so I dont know which one
it is) in a known class for a known object in the database, is there
anyway I can change the data for that column without doing a bunch of
if statements trying to figure out which column it actually is.  So
for example,
I have t = 'bar' and foo = modelName.objects.get(id = 4)
I want to do something like:
foo.t = "new value" or foo[t] = "new value" (but those dont work).
rather than writing a bunch of if statements like
if t = 'modelfieldone'
...
elif t = 'bar'
...
etc.

Is there anyway to do this?

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



jquery grid and django

2011-02-03 Thread Tony
I found a plugin that combines the two but you cant look at the source
unless you have been approved by the creator.  Is there any viable,
simple way to use the jquery grid plugin with django fairly quickly?

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



chrome extension

2011-02-15 Thread Tony
Hi,
Is there any way to have a chrome extension with a backend in Django,
like for storing data server side and using its views?  Or is this not
possible?
thanks

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



authentication

2011-03-09 Thread Tony
I have been looking into django-socialauth and am wondering how well
it works.  Another question I have about it is, if these users log in
with their accounts from other sites, what is the best way for me to
store their data and keep track of them?  Thanks for the help.

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



suspiciousoperation with file upload on django-cms

2011-03-22 Thread Tony
I am using django-cms for my project right now and I am using their
file and image plugins on my pages, but when I try to upload a file, I
get a suspiciousoperation error.  I have looked at my media_url and
media_root, and played with them but I haven't been able to have any
success.  There is also a django cms media root which I have played
with too.  I have gotten this error on the dev server as well as
apache.  I have set file upload permissions to 0644 as well (which was
recommended by others with similar problems).  All other media files
work properly.  Here is my traceback.


Environment:

Request Method: POST
Request URL: 
http://localhost:8000/admin/cms/page/1/edit-plugin/13/?popup=true&no_preview
Django Version: 1.2.4
Python Version: 2.7.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'menus',
 'mptt',
 'appmedia',
 'south',
 'cms.plugins.text',
 'cms.plugins.picture',
 'cms.plugins.link',
 'cms.plugins.file',
 'cms.plugins.snippet',
 'cms.plugins.googlemap',
 'publisher',
 'myproject.polls',
 'social_auth',
 'registration',
 'voting',
 'cms']
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',
 'cms.middleware.page.CurrentPageMiddleware',
 'cms.middleware.user.CurrentUserMiddleware',
 'cms.middleware.toolbar.ToolbarMiddleware',
 'cms.middleware.media.PlaceholderMediaMiddleware')


Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in
get_response
  100. response = callback(request,
*callback_args, **callback_kwargs)
File "C:\Python27\lib\site-packages\django\utils\decorators.py" in
_wrapped_view
  76. response = view_func(request, *args,
**kwargs)
File "C:\Python27\lib\site-packages\django\views\decorators\cache.py"
in _wrapped_view_func
  78. response = view_func(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\contrib\admin\sites.py" in
inner
  190. return view(request, *args, **kwargs)
File "C:\Python27\lib\site-packages\cms\admin\pageadmin.py" in
edit_plugin
  1239. response = plugin_admin.add_view(request)
File "C:\Python27\lib\site-packages\django\utils\decorators.py" in
_wrapper
  21. return decorator(bound_func)(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\utils\decorators.py" in
_wrapped_view
  76. response = view_func(request, *args,
**kwargs)
File "C:\Python27\lib\site-packages\django\utils\decorators.py" in
bound_func
  17. return func(self, *args2, **kwargs2)
File "C:\Python27\lib\site-packages\django\db\transaction.py" in
_commit_on_success
  299. res = func(*args, **kw)
File "C:\Python27\lib\site-packages\django\contrib\admin\options.py"
in add_view
  821. self.save_model(request, new_object, form,
change=False)
File "C:\Python27\lib\site-packages\cms\plugin_base.py" in save_model
  169. return super(CMSPluginBase, self).save_model(request,
obj, form, change)
File "C:\Python27\lib\site-packages\django\contrib\admin\options.py"
in save_model
  623. obj.save()
File "C:\Python27\lib\site-packages\cms\models\pluginmodel.py" in save
  206. super(CMSPlugin, self).save()
File "C:\Python27\lib\site-packages\django\db\models\base.py" in save
  456. self.save_base(using=using, force_insert=force_insert,
force_update=force_update)
File "C:\Python27\lib\site-packages\django\db\models\base.py" in
save_base
  542. for f in meta.local_fields]
File "C:\Python27\lib\site-packages\django\db\models\fields\files.py"
in pre_save
  255. file.save(file.name, file, save=False)
File "C:\Python27\lib\site-packages\django\db\models\fields\files.py"
in save
  92. self.name = self.storage.save(name, content)
File "C:\Python27\lib\site-packages\django\core\files\storage.py" in
save
  47. name = self.get_available_name(name)
File "C:\Python27\lib\site-packages\django\core\files\storage.py" in
get_available_name
  73. while self.exists(name):
File "C:\Python27\lib\site-packages\django\core\f

Re: suspiciousoperation with file upload on django-cms

2011-03-23 Thread Tony
It uses my CMS_PAGE_MEDIA_PATH, which is 'C:\Users\Tony\Documents\My
Music\1'.  Maybe this is the problem, but I dont know how to
explicitely tell Django to use my MEDIA_ROOT.

On Mar 22, 8:45 pm, Karen Tracey  wrote:
> On Tue, Mar 22, 2011 at 5:12 PM, Tony  wrote:
> >  I have looked at my media_url and
> > media_root, and played with them but I haven't been able to have any
> > success.
>
> MEDIA_URL isn't relevant for the problem you are reporting. MEDIA_ROOT is.
> It would help people help you if you shared what value you have been trying
> for MEDIA_ROOT.
>
> Karen
> --http://tracey.org/kmt/

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



embedding tag in another tag

2011-03-23 Thread Tony
I have two tags, and I am trying to put together a dynamic form action
url.  For the url to come together lke I want, one would be embedded
in the other, but when i try to do it this way, I get a parsing
error.  I've also tried using javascript and variables but the tags
dont read the variable like it should, it just reads the actual
variable name.  Are there any possible work arounds?

-- 
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: suspiciousoperation with file upload on django-cms

2011-03-23 Thread Tony
Ive tried it the other way but when it appends the filename the final
slash is the other way.  Either way, the octal thing you said hasn't
had an effect Im pretty sure.  The url in the error message appears to
be the path it should be.  Is there any other reason?

On Mar 23, 4:10 pm, Karen Tracey  wrote:
> On Wed, Mar 23, 2011 at 3:26 PM, Tony  wrote:
> > It uses my CMS_PAGE_MEDIA_PATH, which is 'C:\Users\Tony\Documents\My
> > Music\1'.  Maybe this is the problem, but I dont know how to
> > explicitely tell Django to use my MEDIA_ROOT.
>
> Assuming that string is literally what you are using in your settings,
> replace the backslashes with forward slashes. \1 is interpreted as an octal
> escape sequence, which you do not want.
>
> Karen
> --http://tracey.org/kmt/

-- 
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: embedding tag in another tag

2011-03-23 Thread Tony
there is a form called F, and I am trying to set its "action"
attribute dynamically with javascript.  I can do this successfully.
However, when I try to use one tag in another like this: url_1 = {%
page_url '{% page_attribute "slug"%}/{{id}}/vote/' %} (these are
django-cms tags), I get a parsing error.  Ive also tried to put '{%
page_attribute "slug"%}/{{id}}/vote/' into a variable (url_2) and do
{% page_url url_2 %}, but the tag didn't recognize the variable as a
variable but took url_2 as a null.  Is there anything I can do to get
this to parse correctly?  Do I have to go into the django-cms template
tags folder and change the code?  That seems like it could get messy.

On Mar 23, 1:18 pm, delegb...@dudupay.com wrote:
> What exactly are you trying to get done or achieve?
>
> If that is known, we could be able to help.
> Sent from my BlackBerry wireless device from MTN
>
>
>
>
>
>
>
> -Original Message-
> From: Tony 
>
> Sender: django-users@googlegroups.com
> Date: Wed, 23 Mar 2011 13:06:13
> To: Django users
> Reply-To: django-users@googlegroups.com
> Subject: embedding tag in another tag
>
> I have two tags, and I am trying to put together a dynamic form action
> url.  For the url to come together lke I want, one would be embedded
> in the other, but when i try to do it this way, I get a parsing
> error.  I've also tried using javascript and variables but the tags
> dont read the variable like it should, it just reads the actual
> variable name.  Are there any possible work arounds?
>
> --
> 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 
> athttp://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.



model manager and request

2011-03-30 Thread Tony
Is there a way to use the "request.user" attributes in a custom model
manager?  So I could filter by certain attributes the current logged
in user has?  This is the preferable way I would like to filter the
objects the user sees, so if there is a way, I would appreciate the
help.  If there is no way to do it like this, I would be open to other
suggestions although, the way my project is structured I dont want to
do this in my view functions.
thanks for any help

-- 
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 manager and request

2011-03-30 Thread Tony
yeah, shawn said the exact dilemma I am having.  I am working with a
plugged in app and dont want to change its code and mess with its
views and create a new fork, it just seems like small thing to make a
change for (and I would probably mess something else up).

On Mar 30, 11:58 am, Shawn Milochik  wrote:
> Jacob,
>
> This sort of thing comes up so frequently on this list that we've all
> seen those answers dozens of times, although not usually in so concise
> a manner.
>
> My question, to which there seems to be no answer, is what a good
> approach to do something that I know (from spending a long time on
> this list) is also in high demand: Storing audit information.
>
> Simple requirement:
>     Store datetime.now(), request.user, and changes to a model
> automatically on post_save.
>
> Problem:
>     The "correct" solutions do not work. If you're using any pluggable
> apps at all you have to fork them or not log them. Refactoring is not
> an option.
>
> I understand why request information is simply not in scope in
> models.py. This isn't a rant or a demand for a fundamental change to
> the way Django works. I'm just looking for either:
>
>     1. A definitive "This is currently impossible in Django."
>
>     2. This is possible with this clever hack/middleware/pseudocode/whatever.
>
> Obviously this method (should it exist) allows a lot of bad designs in
> Django apps. But for the case of applying automatic logging in a
> Django project, it seems like a reasonable desire. Especially given
> that, as Django is a Web framework, there is always a request and
> always a user (even if it's an anonymous user).
>
> Your thoughts would be greatly appreciated. I'll also be attending
> your webinar tomorrow. If you find this question to be in scope or
> have extra time then I'd love to see it addressed.
>
> Thank you,
> Shawn

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



unique identifier to distinguish an instance

2011-04-06 Thread Tony
so I have two models, A and B.  B has a foreignkey relationship in it
from A (To be clear because I know I dont explain it that well, one A
has many Bs).  for each group of Bs each A is connected with, I want
there to be a way to mark one of the Bs as unique from the rest of
them.  I added in an extra field called unique_identifier that is a
booleanfield. The problem is I dont know the best way to go about
making sure there is only one B instance marked True for the
unique_identifier field for each set of Bs.  What would be a good way
to ensure there is one and only one instance marked True?

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



Let users either upload a file or provide an URL to a file

2018-01-17 Thread Tony
 

I would like to let users either upload a video file(to AWS S3) or provide 
an URL to a video, e.g. Youtube/Vimeo.


I found a similar question for Rails: Rails: upload a file OR store a url 





But how do I do that in Django(1.11)?


Should I create 2 separate models, or model inheritance with abstract 
model, let users choose what they want to do in the frontend, then display 
the appropriate form?

class VideoModel(models.Model):
title = models.CharField(max_length=200)
post_by = models.OneToOneField(settings.AUTH_USER_MODEL)
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)

class Meta:
abstract = True
class VideoFile(VideoModel):
video = models.FileField(upload_to='uploads/')
class Videolink(VideoModel):
URL = URLField(max_length=200)

Would it be better if there is only 1 model with both a FileField and 
URLField. They are both set to blank = true. Put a message on the page, 
saying either upload a file or provide a Youtube link. In the backend, 
check the request.POST whether one of these fields is filled in, if not, 
render the form again with an error message.


Which one is better to handle such situation? Or they are equally horrible? 
I couldn't think of a third option.

-- 
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/31186b81-e108-47f9-8594-a140dcad3097%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Let users either upload a file or provide an URL to a file

2018-01-17 Thread Tony
Thank you so much. I will give that go.


On Wednesday, January 17, 2018 at 4:48:24 PM UTC+1, Matemática A3K wrote:
>
>
>
> On Wed, Jan 17, 2018 at 11:53 AM, Tony 
> > wrote:
>
>> I would like to let users either upload a video file(to AWS S3) or 
>> provide an URL to a video, e.g. Youtube/Vimeo.
>>
>>
>> I found a similar question for Rails: Rails: upload a file OR store a url 
>> <https://stackoverflow.com/questions/13547724/rails-upload-a-file-or-store-a-url>
>>
>>
>>
>> <https://stackoverflow.com/questions/13547724/rails-upload-a-file-or-store-a-url>
>>
>> But how do I do that in Django(1.11)?
>>
>>
>> Should I create 2 separate models, or model inheritance with abstract 
>> model, let users choose what they want to do in the frontend, then display 
>> the appropriate form?
>>
>> class VideoModel(models.Model):
>> title = models.CharField(max_length=200)
>> post_by = models.OneToOneField(settings.AUTH_USER_MODEL)
>> created = models.DateTimeField(auto_now_add=True)
>> modified = models.DateTimeField(auto_now=True)
>>
>> class Meta:
>> abstract = True
>> class VideoFile(VideoModel):
>> video = models.FileField(upload_to='uploads/')
>> class Videolink(VideoModel):
>> URL = URLField(max_length=200)
>>
>>  
>
>> Would it be better if there is only 1 model with both a FileField and 
>> URLField.
>>
> IMO, yes, indeed 
>
>> They are both set to blank = true. Put a message on the page, saying 
>> either upload a file or provide a Youtube link. In the backend, check the 
>> request.POST whether one of these fields is filled in, if not, render the 
>> form again with an error message.
>>
> class VideoModel(models.Model):
> title = models.CharField(max_length=200)
> post_by = models.OneToOneField(settings.AUTH_USER_MODEL)
> created = models.DateTimeField(auto_now_add=True)
> modified = models.DateTimeField(auto_now=True)video = 
> models.FileField(upload_to='uploads/', blank=True, null=True)
> url = URLField(max_length=200, blank=True, null=True)
>
> def clean(self):
>
> super().clean()
>
> if not self.url and not self.video:
>
>  raise(ValidationError({"url": "Both url and video can't be 
> null"})
>
>  def get_video_url(self):
>
>  return(url if self.url else self.video.url)
>
>  
>  This is a way of doing it. If you use a ModelForm, then it will show the 
> error message automatically. You can add some javascript for showing only 
> the one that was chosen. You should have for convenience a function or 
> method that return the url for the video independently of the source.
>
>>
>> Which one is better to handle such situation? Or they are equally 
>> horrible? I couldn't think of a third option.
>>
>> -- 
>> 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/31186b81-e108-47f9-8594-a140dcad3097%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/31186b81-e108-47f9-8594-a140dcad3097%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/04d21929-59cb-4c18-b8ae-118cc92aaa4c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Let users either upload a file or provide an URL to a file

2018-01-17 Thread Tony
Thank you so much. I will give it a go.

On Wednesday, January 17, 2018 at 4:48:24 PM UTC+1, Matemática A3K wrote:
>
>
>
> On Wed, Jan 17, 2018 at 11:53 AM, Tony 
> > wrote:
>
>> I would like to let users either upload a video file(to AWS S3) or 
>> provide an URL to a video, e.g. Youtube/Vimeo.
>>
>>
>> I found a similar question for Rails: Rails: upload a file OR store a url 
>> <https://stackoverflow.com/questions/13547724/rails-upload-a-file-or-store-a-url>
>>
>>
>>
>> <https://stackoverflow.com/questions/13547724/rails-upload-a-file-or-store-a-url>
>>
>> But how do I do that in Django(1.11)?
>>
>>
>> Should I create 2 separate models, or model inheritance with abstract 
>> model, let users choose what they want to do in the frontend, then display 
>> the appropriate form?
>>
>> class VideoModel(models.Model):
>> title = models.CharField(max_length=200)
>> post_by = models.OneToOneField(settings.AUTH_USER_MODEL)
>> created = models.DateTimeField(auto_now_add=True)
>> modified = models.DateTimeField(auto_now=True)
>>
>> class Meta:
>> abstract = True
>> class VideoFile(VideoModel):
>> video = models.FileField(upload_to='uploads/')
>> class Videolink(VideoModel):
>> URL = URLField(max_length=200)
>>
>>  
>
>> Would it be better if there is only 1 model with both a FileField and 
>> URLField.
>>
> IMO, yes, indeed 
>
>> They are both set to blank = true. Put a message on the page, saying 
>> either upload a file or provide a Youtube link. In the backend, check the 
>> request.POST whether one of these fields is filled in, if not, render the 
>> form again with an error message.
>>
> class VideoModel(models.Model):
> title = models.CharField(max_length=200)
> post_by = models.OneToOneField(settings.AUTH_USER_MODEL)
> created = models.DateTimeField(auto_now_add=True)
> modified = models.DateTimeField(auto_now=True)video = 
> models.FileField(upload_to='uploads/', blank=True, null=True)
> url = URLField(max_length=200, blank=True, null=True)
>
> def clean(self):
>
> super().clean()
>
> if not self.url and not self.video:
>
>  raise(ValidationError({"url": "Both url and video can't be 
> null"})
>
>  def get_video_url(self):
>
>  return(url if self.url else self.video.url)
>
>  
>  This is a way of doing it. If you use a ModelForm, then it will show the 
> error message automatically. You can add some javascript for showing only 
> the one that was chosen. You should have for convenience a function or 
> method that return the url for the video independently of the source.
>
>>
>> Which one is better to handle such situation? Or they are equally 
>> horrible? I couldn't think of a third option.
>>
>> -- 
>> 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/31186b81-e108-47f9-8594-a140dcad3097%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/31186b81-e108-47f9-8594-a140dcad3097%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

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


How to test get_success_url in CreateView in Django

2018-02-07 Thread Tony


I am trying to write a test for the get_success_url method in a CreateView, 
to make sure it redirects to the newly created page. But the response 
status code is 200 instead of 302 as I expected.

views.py

class BlogCreate(CreateView):
model = Blog
fields = [‘author’, 'title', ’post’]
def get_success_url(self):
return reverse_lazy('blog:blog-detail', kwargs={'slug': 
self.object.slug})
class BlogList(ListView):
model = Blog
ordering = ["-created"]

class BlogDetail(DetailView):
model = Blog

config/urls.py

from django.conf.urls import include, url

urlpatterns = [
url(r'^blog/', include('blog.url', namespace='blog')),

blog/urls.py

from django.conf.urls import urlfrom .views import BlogCreate, BlogList, 
BlogDetail, BlogEdit, BlogDelete


urlpatterns = [
url(r'^(?P[-\w]+)/$', BlogDetail.as_view(), name='blog-detail'),
url(r'^(?P[-\w]+)/edit$', BlogEdit.as_view(), name='blog-edit'),
url(r'^(?P[-\w]+)/delete$', BlogDelete.as_view(), name='blog-delete'),
url(r'^new$', BlogCreate.as_view(), name='blog-create'),
url(r'^$', BlogList.as_view(), name='blog-list'),]

tests.py

class BlogCreateTest(TestCase):
def setUp(self):
self.user = User.objects.create_user(username='john', password='123')

def test_create_success_url(self):
post = {‘author’: self.user,
'title': ‘new blog’,
‘article’: ‘text’,
}

url = reverse_lazy('blog:blog-create')

success_url = reverse_lazy('blog:blog-detail', 
kwargs={'slug':'new-blog'})
response = self.client.post(url, post)

self.assertEqual(response.status_code, 302)
self.assertRedirects(response, success_url)

-- 
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/9521294e-a64e-4015-a3b7-9bf1d34c3cd0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Not raising exception when using form_class in generic CreateView

2018-02-11 Thread Tony
Hi, I am using a package called Django Embed Video 
 for my project. It comes 
with a EmbedVideoField for the model and validation for the URL which 
checks whether the URL is Youtube or Vimeo.
It raises exceptions when using generic create view without using 
customised form(form_class). However, when I use a customised form because 
I want to customise the widgets and css classes, it doesn't raise any 
exceptions. Why is that? Is there a way get the exceptions working with 
form_class?

Another thing is that the data is saved to the db which I can see in Django 
admin. But it is not included in the generic list view. Why?

*models.py*

from django.db import models

from embed_video.fields import EmbedVideoField


Class Video(models.Model):

   title = models.CharField(max_length=30)

   description = models.TextField(blank=True)

   url = EmbedVideoField(verbose_name=‘video’)



*views.py*

from django.views.generic.edit import CreateView

from django.views.generic.list import ListView


class VideoCreate(CreateView):

   model = Video

   form_class = NewVideoForm

class VideoList(ListView):

   model = Video

   ordering = ["-created"]


*forms.py*

from django import forms

from .models import Video


class NewVideoForm(forms.ModelForm):

   description = forms.CharField(widget=forms.Textarea(),

   required=False,

   max_length=4000,

   help_text='The max length of the text is 
4000.')

   url = forms.URLField(label='video', help_text='Please enter a Youtube or 
Vimeo link.')


class Meta:

   model = Video

   fields = ['title', 'description', 'url']

-- 
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/036a9a78-960b-44f0-87ca-795168629785%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Overrding queryset on a field in form generated with ModelForm

2008-12-10 Thread Tony Chu

Hi All,

I was using the ModelForm to generate my first form in Django.
ModelForm is great.  However, I had wanted to dynamically limit the
selection of Foreign keys to a subset I generate.

The only way I found after a lot of trial and error was the following:

form['foreignkey'].field.queryset = desiredQuerySetFromForeignKey

Is this a good way to do it?  Or is there some reason why this isn't
mentioned in the documentations?

More importantly, is there a better, more idiomatic 'Django' way to do
this?

Thanks for your time.

Tony

--~--~-~--~~~---~--~~
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: Overrding queryset on a field in form generated with ModelForm

2008-12-26 Thread Tony Chu

Thank you very much Malcolm. The methods I listed above has worked for
me so far - so your response is reassuring.

I was just surprised that no one had encountered a similar need
already.  The concept here is parallel to getting a list of
territories in a country, dynamically fetched based on the country
specified.  That would appeared to me to be a fairly common pattern.

Yours,
Tony

On Dec 10, 5:38 pm, Malcolm Tredinnick 
wrote:
> On Wed, 2008-12-10 at 00:18 -0800, Tony Chu wrote:
> > Hi All,
>
> > I was using the ModelForm to generate my first form in Django.
> > ModelForm is great.  However, I had wanted to dynamically limit the
> > selection of Foreign keys to a subset I generate.
>
> > The only way I found after a lot of trial and error was the following:
>
> > form['foreignkey'].field.queryset = desiredQuerySetFromForeignKey
>
> > Is this a good way to do it?
>
> There's a lot of text below, but my short answer is "looks fine to me."
> That might, of course, be why nobody trusts my opinion, so be
> responsible for your own actions.
>
> >  Or is there some reason why this isn't
> > mentioned in the documentations?
>
> Not every single possibility for setting parameters is mentioned in the
> documentation. Sometimes because nobody's provided documentation for it
> yet. Sometimes because those possibilities are sufficiently edge-case
> that documenting them would obscure the necessary pieces (which means
> documenting them really has to go into a separate section and still be
> findable). At some level, looking at the __init__ methods for field
> classes isn't that hard to do (it's pretty normal Python practice, too).
>
> Basically, documentation on various levels, given that we're catering
> for everybody from experienced Django users to people just learning
> Python and all stages in between, is an ongoing process.
>
> If you want to take a swing at writing more comprehensive documentation
> in this area, please do! We welcome genuine documentation improvements.
> As I note above, the hard bit is working out a structure so that all the
> necessary reference material is available (since you're really after a
> piece of reference documentation), without making the existing "howto"
> stuff less comprehensible. That's another ongoing problem we wrestle
> with and something that is very much ongoing work (it's easier to fix
> now that the docs have been restructured prior to 1.0, but it's by no
> means finished work).
>
> > More importantly, is there a better, more idiomatic 'Django' way to do
> > this?
>
> Without wanting to stamp anything as "more idiomatic", I'll say this
> (it's in two parts, so bear with me whilst the first bit looks like a
> non-solution): the reasonably standard approach if you want to change
> the field used by default in a ModelForm is to override that field.
> ForeignKeys in models are represented by ModelChoiceFields (that's
> documented in topcs/forms/models) which accept a queryset parameter. So
> you can override the field and specify whatever queryset you like.
>
> However, since you want to do this dynamically, you need to work out how
> to effect the same behaviour at form build time (i.e. in __init__). So
> the solution you've come up with is essentially the most logical: at
> instance creation, get the field object you're interested in and change
> the affected parameter. I can't see that there's anything wrong with
> that approach. As much as possible classes tend to be designed (not just
> in Django, but as a trend in Python) so that parameters can be set up by
> writing to attributes or calling particular methods -- that is, modified
> at runtime, not just at definition.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Developer Designer Job in NYC

2009-04-13 Thread Tony Haile

We're looking for a developer with Django and CSS skills to come work
on Chartbeat.com. Chartbeat is a Betaworks company, the people behind
Bit.ly, Summize, Tweetdeck and a whole hos of other companies. Email
me at tony at betaworks.com. Job description below:

Chartbeat provides real-time analytics for your website, allowing you
to react instantly and effectively as visitors interact with your
site. We tell you how many people on your site and what they are doing
as they do it in real time. What’s more, we’ll send you alerts when
extraordinary activity takes place whether it’s uptime, user load time
or a flood of visitors exceeding your average maximum.

Chartbeat launched at the Web 2.0 Expo Keynote and has had an
incredible response. Now we’re looking for a superb front end designer-
developer to lead Chartbeat’s growth from newly-launched beta to fully-
fledged can’t live without it real-time analytics service.

Chartbeat is an early-stage company within the Betaworks Studios, the
early stage accelerator that has also been behind bit.ly, Tweetdeck
and Summize. You would be working out of the Betaworks loft in the
Meatpacking district of Manhattan (complete with full size pool table)
and getting the chance to interact with people from other companies
within the Betaworks stable. It’s a great mashup of some of the
brightest and best companies in the industry today.

What we use:

- CSS/HTML
- Django/Python
- Linux
- Javascript
- Flash
- Canvas
- Silverlight
- Amazon Web Services


We want to hear from you if:

- Your CSS mastery inspires awe in all who see it
- You are a creative product visionary who groks the real-time web
- You are passionate about metrics
- You have extensive experience of agile product development and
working in small teams that get things done on time.

Roles and responsibilities

- You will own the front-end of Chartbeat, shaping the look and
functionality of the service as it evolves.
- You will be in charge of the Chartbeat API and working with our
partners and resellers to integrate Chartbeat’s functionality into a
host of other services.
- You will work closely with the System Architect to ensure a
consistent stable service for our clients.




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



how to control access the urls like : r'django/\w+'

2009-06-18 Thread lee tony
Hi all,

I am new to django. Now I have a problem:
When someone hasn't the authority to access some urls(like:
r'test/\w+').
How can I control it?
Should I use the "requst.user.has_perm()" in all apps belonged to
"test"?
Is there any shortcut?


Thanks in advaced!

--~--~-~--~~~---~--~~
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: multi-db vs. data warehouse

2009-09-23 Thread Tony Schmidt

Hi, Nausikaa.  Thanks for your reply.

Unfortunately, the legacy systems must remain in place until they are
gradually (if ever) phased out.  There's a whole bunch of
functionality that I don't want to have to recreate in those systems
(POS, inventory/accounting, products, etc.).  I just want to build new
functionality that accesses that data (like the example of an order
entry form that creates new order/item data entities in a new DB with
keys to entities in the other DBs or to their versions in the
warehouse).  Most of it should be read only.

I'm starting to hear that a data warehouse is the way to go - but then
there's the question of data warehouse vs. data mart, Inmon vs.
Kimball, and how I can get started building one in python.  I'm not
hearing many suggestions for the multi-db approach (which makes me
wonder what the Django muli-db branch is for?)

On Sep 22, 2:01 am, nausikaa  wrote:
> Hi snfctech
>
> With warehouse I assume you mean keeping the datasources and periodic
> transfer into a central db (the warehouse).
> Why not migrate all your datasources into e.g. a PostgreDQL db?
> It is easy to write forms and implement logins/access rights in
> django so that your non-technical users can read or edit the
> data. Besides you'd remove some (unnecessary) heterogenity and thereby
> complexity from your system.
> But since I don't know your system I might be missing the point
> completely.
>
> Nausikaa
>
> On Sep 22, 3:10 am, snfctech  wrote:
>
> > I understand that there is a Django branch being actively worked on
> > for connections to multiple DB vendors, or that Django + Elixir may be
> > a good option.  But I'm wondering if building a single data warehouse
> > may still be a better way to go?
>
> > Here's an example of some of the relations I'm going to have to build
> > for my project:
>
> > I've got order and order_item tables with their own data and relations
> > to members (Access DB), products (flat file) and employees (MySQL).
>
> > I initially thought that the best way to manage this would be to
> > create a new DB for the order and order_item tables, and then create
> > cross-vendor joins in the ORM.  But then I came across an unexpected
> > advantage of having all the data in an updated warehouse - my semi-
> > technical staff could still use products like OOBase, that are limited
> > to a single vendor connection, to make reports and forms based on the
> > warehouse data.
>
> > So now I'm wondering - are direct connections to multiple databases
> > really the best way to go?  Or are there more advantages to building a
> > data warehouse (keeping in mind the complexities of the data
> > replication, scripts for pushing and pulling data, etc.)
>
> > Thanks in advance for any tips.
--~--~-~--~~~---~--~~
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: multi-db vs. data warehouse

2009-09-23 Thread Tony Schmidt

Thanks for your reply, Joshua.

Complexity is exactly what I'm trying to avoid - but after doing a
little research on data warehouses (I've never built one), that seems
like a very complex route as well!

I would like to just come up with my "dream schema" and run update
scripts on a daily or event-driven basis, but there seem to be a
million concepts related to data warehousing: data marts, dimensions,
star schemas, snowflakes, EAV tables, and so on.

It seems more straight forward if I could just connect directly to the
operational systems.  I wonder if all that theory is really necessary
for a basic data warehouse...

On Sep 23, 12:09 pm, Joshua Russo  wrote:
> The multi-db branch is just now in the process of being baked into the core
> and from what I can tell it's not quite done yet. Even when it is completely
> done I would recommend the data warehouse approach. I view the multi-db
> functionality more as a last resort, where you really don't have an option
> to merge the data. It adds a lot of complexity so if you can do without I
> would recommend an alternative.
> Just my 2 cents
> Josh
>
> On Wed, Sep 23, 2009 at 4:05 PM, Tony Schmidt wrote:
>
>
>
> > Hi, Nausikaa.  Thanks for your reply.
>
> > Unfortunately, the legacy systems must remain in place until they are
> > gradually (if ever) phased out.  There's a whole bunch of
> > functionality that I don't want to have to recreate in those systems
> > (POS, inventory/accounting, products, etc.).  I just want to build new
> > functionality that accesses that data (like the example of an order
> > entry form that creates new order/item data entities in a new DB with
> > keys to entities in the other DBs or to their versions in the
> > warehouse).  Most of it should be read only.
>
> > I'm starting to hear that a data warehouse is the way to go - but then
> > there's the question of data warehouse vs. data mart, Inmon vs.
> > Kimball, and how I can get started building one in python.  I'm not
> > hearing many suggestions for the multi-db approach (which makes me
> > wonder what the Django muli-db branch is for?)
>
> > On Sep 22, 2:01 am, nausikaa  wrote:
> > > Hi snfctech
>
> > > With warehouse I assume you mean keeping the datasources and periodic
> > > transfer into a central db (the warehouse).
> > > Why not migrate all your datasources into e.g. a PostgreDQL db?
> > > It is easy to write forms and implement logins/access rights in
> > > django so that your non-technical users can read or edit the
> > > data. Besides you'd remove some (unnecessary) heterogenity and thereby
> > > complexity from your system.
> > > But since I don't know your system I might be missing the point
> > > completely.
>
> > > Nausikaa
>
> > > On Sep 22, 3:10 am, snfctech  wrote:
>
> > > > I understand that there is a Django branch being actively worked on
> > > > for connections to multiple DB vendors, or that Django + Elixir may be
> > > > a good option.  But I'm wondering if building a single data warehouse
> > > > may still be a better way to go?
>
> > > > Here's an example of some of the relations I'm going to have to build
> > > > for my project:
>
> > > > I've got order and order_item tables with their own data and relations
> > > > to members (Access DB), products (flat file) and employees (MySQL).
>
> > > > I initially thought that the best way to manage this would be to
> > > > create a new DB for the order and order_item tables, and then create
> > > > cross-vendor joins in the ORM.  But then I came across an unexpected
> > > > advantage of having all the data in an updated warehouse - my semi-
> > > > technical staff could still use products like OOBase, that are limited
> > > > to a single vendor connection, to make reports and forms based on the
> > > > warehouse data.
>
> > > > So now I'm wondering - are direct connections to multiple databases
> > > > really the best way to go?  Or are there more advantages to building a
> > > > data warehouse (keeping in mind the complexities of the data
> > > > replication, scripts for pushing and pulling data, etc.)
>
> > > > Thanks in advance for any tips.
--~--~-~--~~~---~--~~
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: multi-db vs. data warehouse

2009-09-24 Thread Tony Schmidt

Well, I guess the answer to the thread is looking like:

- a data warehouse is preferable to multiple db connections and cross-
vendor joins

But that's only because I haven't heard anyone voice support for the
multi-db idea.

Now the question is:

How should the warehouse be constructed in tandem with new
functionality and data entities?

What I've read about data warehouses seems to limit them to read-only
OLAP, with special data modelling (namely dimensional, as opposed to
the ER modelling I'm used to).  But in the example I give in my first
post, I'm talking about creating new order and order_item data with
keys to data in the warehouse.  Should that data be stored in the
warehouse, as well, so I don't have to go back to multiple db
connections for my joins?  If it co-exists with the read-only data,
should it all be modelled the same? (all ER or all dimensional)  Or
can it be mixed?

I would start a new thread, but whereas the multi-db issue related
directly to developing Django technology, I'm not sure the issue of
the warehouse design is an appropriate topic for this group (although
I'm also not sure where I should discuss it).

On Sep 24, 2:36 am, Joshua Russo  wrote:
> If he wants to discuss it here I can do that too. It was just a little off
> topic, but not not too much I suppose.
>
> On Thu, Sep 24, 2009 at 7:41 AM, nausikaa  wrote:
>
> > Hi Joshua
>
> > Thanks for sharing your knowledge.
> > Too bad, I would've liked to read your suggestion to Tony as well. ; )
> > I'm a just graduate and at work I'm working on something very similar
> > to what has been discussed here.
>
> > On Sep 23, 9:51 pm, Joshua Russo  wrote:
> > > I have many years of database design experience and it sounds like you
> > are
> > > getting lost in terminology.
> > > I would start out with a set of tables in the warehouse that mirror the
> > > existing data. In these tables you can either wipe and reload each time,
> > or
> > > create a mechanism to track each individual load.
>
> > > You can then simply write your application against these tables or if you
> > > feel adventurous you can add a more unified set of tables with linking
> > > foreign keys and such and have your process also update the cleaner/more
> > > unified data set. This second part get's tricky and takes practice to
> > know
> > > you have a good structure. You will also have to track changes,
> > additions,
> > > and deletions. If you want some help or advice I would be happy to take a
> > > gander at your structures to show you what I might do. Feel free to email
> > me
> > > directly at josh.r.ru...@gmail.com.
>
> > > On Wed, Sep 23, 2009 at 6:35 PM, Tony Schmidt  > >wrote:
>
> > > > Thanks for your reply, Joshua.
>
> > > > Complexity is exactly what I'm trying to avoid - but after doing a
> > > > little research on data warehouses (I've never built one), that seems
> > > > like a very complex route as well!
>
> > > > I would like to just come up with my "dream schema" and run update
> > > > scripts on a daily or event-driven basis, but there seem to be a
> > > > million concepts related to data warehousing: data marts, dimensions,
> > > > star schemas, snowflakes, EAV tables, and so on.
>
> > > > It seems more straight forward if I could just connect directly to the
> > > > operational systems.  I wonder if all that theory is really necessary
> > > > for a basic data warehouse...
>
> > > > On Sep 23, 12:09 pm, Joshua Russo  wrote:
> > > > > The multi-db branch is just now in the process of being baked into
> > the
> > > > core
> > > > > and from what I can tell it's not quite done yet. Even when it is
> > > > completely
> > > > > done I would recommend the data warehouse approach. I view the
> > multi-db
> > > > > functionality more as a last resort, where you really don't have an
> > > > option
> > > > > to merge the data. It adds a lot of complexity so if you can do
> > without I
> > > > > would recommend an alternative.
> > > > > Just my 2 cents
> > > > > Josh
>
> > > > > On Wed, Sep 23, 2009 at 4:05 PM, Tony Schmidt <
> > tschm...@sacfoodcoop.com
> > > > >wrote:
>
> > > > > > Hi, Nausikaa.  Thanks for your reply.
>
> > > > > > Unfortunately, the legacy systems must remain in place until they
> > are
> > &g

Re: multi-db vs. data warehouse

2009-09-28 Thread Tony Schmidt

"If you need to link one order item to other data in the warehouse it
should
only either be done in the warehouse or between the systems outside of
the
warehouse."

Now we're back to the crux of the topic!  Joins in the warehouse, or
cross-vendor joins between disparate systems?

If multi-db _were_ done, or if multi-db connections with cross-vendor
joins via Elixir were an option, would that be a preferable route to
creating those joins between the order entry system and the
warehouse?  I don't really need the warehouse for what it seems to be
used for traditionally - analytics, reports and BI - I simply need it
to make my life easier when trying to generate order and order_item
records that have foreign key attributes in different systems like
"product_id", "employee_id", "member_id", and so forth.  (Although, as
I mentioned earlier, having a single repository for my OOBase users to
go to would be an added plus.)

So maybe I shouldn't be calling what I need a "warehouse", but rather
a "central data repository with an ETL layer"?  Or maybe I should
throw out the ETL overhead entirely and figure out how to perform
cross-vendor, multi-db joins?

That is still my quandary..


On Sep 26, 7:46 am, Joshua Russo  wrote:
> No one is recommending multi-db because it's not done yet.
>
> I'm not sure I understand exactly what you mean by "creating new order and
> order_item data with keys to data in the warehouse" but that doesn't sound
> like a recommended approach.
> A data warehouse (in my opinion) should be read only and no other system
> should need to know about it. An important concept to keep in mind with a
> warehouse is that it is never the originator of the base data (it may create
> new computations of the data but it's always based on data from other
> systems). As such it is for reporting purposes only and no other system
> should treat it as the system of record.
>
> If you need to link one order item to other data in the warehouse it should
> only either be done in the warehouse or between the systems outside of the
> warehouse. It sounds like you want to modify the order entry application to
> reference data in other systems and still display the data in the order
> entry app. If this is the case the only solution I would implement is
> between the two existing systems.
>
> As far as OLAP goes, it's not mutually exclusive from ER. It is simply a
> method of extracting multidimensional data. An ER model can most certainly
> be dimensional, you just need to integrate the proper timestamp structure.
>
> On Thu, Sep 24, 2009 at 4:35 PM, Tony Schmidt wrote:
>
>
>
> > Well, I guess the answer to the thread is looking like:
>
> > - a data warehouse is preferable to multiple db connections and cross-
> > vendor joins
>
> > But that's only because I haven't heard anyone voice support for the
> > multi-db idea.
>
> > Now the question is:
>
> > How should the warehouse be constructed in tandem with new
> > functionality and data entities?
>
> > What I've read about data warehouses seems to limit them to read-only
> > OLAP, with special data modelling (namely dimensional, as opposed to
> > the ER modelling I'm used to).  But in the example I give in my first
> > post, I'm talking about creating new order and order_item data with
> > keys to data in the warehouse.  Should that data be stored in the
> > warehouse, as well, so I don't have to go back to multiple db
> > connections for my joins?  If it co-exists with the read-only data,
> > should it all be modelled the same? (all ER or all dimensional)  Or
> > can it be mixed?
>
> > I would start a new thread, but whereas the multi-db issue related
> > directly to developing Django technology, I'm not sure the issue of
> > the warehouse design is an appropriate topic for this group (although
> > I'm also not sure where I should discuss it).
>
> > On Sep 24, 2:36 am, Joshua Russo  wrote:
> > > If he wants to discuss it here I can do that too. It was just a little
> > off
> > > topic, but not not too much I suppose.
>
> > > On Thu, Sep 24, 2009 at 7:41 AM, nausikaa  wrote:
>
> > > > Hi Joshua
>
> > > > Thanks for sharing your knowledge.
> > > > Too bad, I would've liked to read your suggestion to Tony as well. ; )
> > > > I'm a just graduate and at work I'm working on something very similar
> > > > to what has been discussed here.
>
> > > > On Sep 23, 9:51 pm, Joshua Russo  wrote:
> > > > > I have many years of database design experience and it

Re: multi-db vs. data warehouse

2009-09-29 Thread Tony Schmidt

Thanks for everyone's feedback.  I think it's time to just give it a
whirl and see what happens.

@Joshua:

"With my personal experience I would go with an ETL and copy the
desired data
directly into your ordering system."

I think that's the approach I'm going to take.

@David:

Thanks for the link.  I'll keep ROA in mind.


On Sep 28, 1:04 pm, Joshua Russo  wrote:
> On Mon, Sep 28, 2009 at 6:36 PM, David Larlet  wrote:
>
> > Le 22 sept. 2009 à 03:10, snfctech a écrit :
> > > I understand that there is a Django branch being actively worked on
> > > for connections to multiple DB vendors, or that Django + Elixir may be
> > > a good option.  But I'm wondering if building a single data warehouse
> > > may still be a better way to go?
>
> > Self-promotion here, but if you eventually choose the data warehouse
> > approach, you should take a look at django-roa:
> >http://code.welldev.org/django-roa/wiki/Home
>
> > It allows you to deal with your HTTP resources as Django models
> > painlessly.
> > Do not hesitate to contact me if that's your final choice, I already
> > use it against a data warehouse.
>
> That looks pretty cool. I will definitely keep that in mind in the future.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Can a model generate custom SQL when loading/saving a field?

2009-11-12 Thread Tony Czeh
I'm running into a bit of a problem with Django's models.  I have a
VARCHAR field that needs to be stored with the content AES_ENCRYPT
then HEXed (done on the MySQL server).

What I'd like to have happen is for the Django model to generate
"AES_DECRYPT(UNHEX(field), salt)" when the field is loded by the model
and "HEX(AES_ENCRYPT(field, salt))" when the field is saved by the
model.

Is there a way to make this happen, so far I'm not turning up
anything.

Cheers,
Tony Czeh

--

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




Re: Multiple level aggregate

2009-11-16 Thread Tony Czeh
On 11/16/09 1:12 PM, despy wrote:
> Hi,
>
> I'm trying to get my head around a complex aggregate query and I could
> do with some help. Say I have the following models
>
> StockMarket
> |
> Stock
> |
> StockPrice
>
> If StockPrice has price and date fields, and one price entry for every
> day for every stock how would I write a query to get the average price
> for a given stockmarket for the last six months?
>
> Thanks
>
> Greig
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=.
>
>

Something along these lines should work in SQL:

SELECT s.stock_symbol
  , AVG(sp.price) AS average_price
FROM Stock s
  LEFT JOIN StockPrice sp
 ON s.id = sp.stock_id
WHERE sp.date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH)
   AND CURRENT_DATE
GROUP BY s.stock_symbol

--

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




Re: Use Subversion to Download the Latest Django Version

2009-11-17 Thread Tony Czeh
TortoiseSVN is a graphical SVN client.  If you right-click you should 
see an option for Tortoise that, when expanded, contains a check out 
option.  From there, just follow the wizard.

Mikey3D wrote:
> I just got new computer Win7 64-bit and I downloaded:
> 
> 64 Bit TortoiseSVN-1.6.6.17493-x64-svn-1.6.6.msi
> 
> After finished download >Restart >Start >Run >cmd
> 
> --
> C:\Users\Mike>svn co http://code.djangoproject.com/svn/django/trunk/
> 'svn' is not recognized as an internal or external command, operable
> program or batch file.
> 
> C:\Users\Mike>
> --
> 
> What should I do?
> 
> Thanks, Mikey3D
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=.
> 
> 

--

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




Django HTTPS and HTTP Sessions

2009-12-10 Thread Tony Thomas
Hi,

I'm using Django 1.1.1 with the ssl redirect middleware.

Sessions data (authentication etc.) created via HTTPS are not
available in the HTTP portions of the site.

What is the best way to make it available without having to make the
entire site HTTPS?

--

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




Re: Track "before" and "after" state of an object when editing in the Admin?

2010-04-27 Thread Tony Czeh
I had a very similar problem where I needed to track all changes to
models throughout the entire application.  I've posted my solution at
http://pastebin.com/2Wc4Nwcd for you to take a look at.

Basically, as was previously suggested, I've hooked into the various
pre_*, post_* and m2m_changed signals that are available.  My code
will log all changes to models unless the model is included in a
DONT_LOG_MODELS tuple in the app settings.  Changes to m2m
relationships are stored against the model containing the m2m.

Hope this helps.

Cheers,
Tony

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



Re: finding current url

2010-07-22 Thread Tony Lambropoulos
thanks you guys, both your answers were very helpful.

2010/7/22 Alexandre González 

> Take a look to django.contrib.sites
> http://djangobook.com/en/2.0/chapter16/
>
> <http://djangobook.com/en/2.0/chapter16/>You can use:
> site.objects.get_current()
>
> I hope that this helps you.
>
> On Thu, Jul 22, 2010 at 22:58, Tony  wrote:
>
>> Hi,
>> So I have many domains pointing to one url.  I am using apache in
>> conjunction with django.  How can I use Django to find out which
>> domain name is the one actually being typed in by the user?  So lets
>> say I have siteone.com and sitetwo.com and both go to the same website
>> that I will call mainsite.com/someDjangoView.  How can I find out if
>> the user typed in siteone.com or sitetwo.com even though they both
>> have the same destination?
>> thanks,
>> Tony
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>
>
> --
> Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx, .ppt
> and/or .pptx
> http://mirblu.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: scaling my site

2010-07-23 Thread Tony Lambropoulos
Well I am new to this, but with a push in the right direction I think i can
set it up and i have a partner who knows a little more.  We're looking for
advice on good hosting sites and database servers that mesh well with Django
and can expand well.  How is slicehost?  has anyone heard anything about
web-lacky?, because I have a partner who currently uses that for his small
stuff.

On Fri, Jul 23, 2010 at 1:18 PM, Greg Pelly  wrote:

> You will need to find/hire a sysadmin if you can't do this yourself. We
> looked into Amazon for our purposes and found their interface kludgy and
> their documentation confusing rather than helpful.  Also, I kept a server
> running idle on Amazon for a month and it was more expensive than slicehost
> ($20/month), which we ultimately chose.  In any event, it sounds like you
> should find a sysadmin to help you with these decisions/tasks.
>
> Greg
>
>
> On Fri, Jul 23, 2010 at 12:43 PM, Tony  wrote:
>
>> I have just about finished all the logic for my site.  In short, I
>> need the site to be pretty fast and a good amount of database storage
>> with the possibility of getting more in the future if and probably
>> when I need it.  Right now I am just testing my website on my computer
>> with Django, (mod_swgi) apache and postgresql.  I should also mention
>> I don't have the money right now to buy my own servers so I've been
>> looking into Amazon S3 and the computing cloud, EC2 but this is my
>> first time doing something like this so I don't know too much about
>> these things.  Anyway, I'm looking for advice on the best way to set
>> this website up and I am leaning toward using amazon's features, but I
>> really need a lot more insight on how all that works.  What database
>> server should I use?  How does S3 and EC2 work?  Should i use a web
>> host like web-lackey.com or something?  I'm a little unaware on how to
>> put something into production and how everything connects.  I accept
>> and appreciate any advice on the matter.
>> Thanks,
>> Tony
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: scaling my site

2010-07-23 Thread Tony Lambropoulos
so I would just run an apache instance on the host?  And on the Amazon
utilities, is it that complicated to set up?  Could you give me some sort of
overview of what that would take?  And if I did just do the apache instance,
would it be fast enough because it sort of does need to be fast and be able
to store a good amount of data.  Thanks by the way for answering my
questions so thoroughly.

On Fri, Jul 23, 2010 at 2:38 PM, Michael  wrote:

> On Fri, Jul 23, 2010 at 4:29 PM, Tony Lambropoulos wrote:
>
>> Well I am new to this, but with a push in the right direction I think i
>> can set it up and i have a partner who knows a little more.  We're looking
>> for advice on good hosting sites and database servers that mesh well with
>> Django and can expand well.  How is slicehost?  has anyone heard anything
>> about web-lacky?, because I have a partner who currently uses that for his
>> small stuff.
>>
>>
> Slicehost has been a wonderful host for me. It will essentially be a fresh
> server, which you will need to deploy yourself. It is really great for
> scaling because you can start small, grow your server instance and if need
> be fire up other instances on the fly to expand from there. Amazon or
> Rackspace (or any other cloud provider) is essentially the same thing.
>
> Serving files through S3 or cloud files is a great way to lower bandwidth
> and load on your server, so I would highly recommend using them, but there
> is no reason to start with it. Start simple with a simple apache instance,
> see if there are problems and fix them as you go along.
>
> I haven't heard anything about web-lacky.
>
> Does this help you out? Let us know if you have any more questions.
>
> I learned this stuff as I went along, and now manage sites that are quite
> large. It isn't easy, there is a lot of learning and stress, but it is very
> possible.
>
> Michael
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



django and legacy database

2010-10-08 Thread tony yu
I have a legacy database and have user and password with plain-text or md5
encryption
Now, I want an app or function, when the user signup, change or reset the
password, the record of legacy databases will change synchronously.
I would like to keep the existing account app, how can I do?

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



[newbie]Apache Deployment Problem

2008-02-06 Thread Tony Winslow

Hi, all!
I installed mod_python and do the configurations as the tutorial on the 
official site. But mod_python still can not find the mysite.settings 
module. What might be the problem?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: [newbie]Apache Deployment Problem

2008-02-06 Thread Tony Winslow

Karen Tracey wrote:
> On Feb 6, 2008 9:11 AM, Tony Winslow <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>> wrote:
>
> Hi, all!
> I installed mod_python and do the configurations as the tutorial
> on the
> official site. But mod_python still can not find the mysite.settings
> module. What might be the problem?
>
>
> Could be apache doesn't have permissions to access your settings file, 
> could be you didn't quite get the config right. If you post details of 
> how you have set things up people would be more likely to be able to 
> spot what the problem is.
>
> Karen
>
>
> >
I set the path to include /path/to/mysite and /var/www.
My App is under /path/to/mysite, and settings.py is at /var/www/mysite 
which is accessible to Apache.

The traceback:

Traceback (most recent call last):

  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1537, in 
HandlerDispatch
default=default_handler, arg=req, silent=hlist.silent)

  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1229, in 
_process_target
result = _execute_target(config, req, object, arg)

  File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1128, in 
_execute_target
result = object(arg)

  File "/usr/lib/python2.5/site-packages/django/core/handlers/modpython.py", 
line 177, in handler
return ModPythonHandler()(req)

  File "/usr/lib/python2.5/site-packages/django/core/handlers/modpython.py", 
line 145, in __call__
self.load_middleware()

  File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py", line 
22, in load_middleware
for middleware_path in settings.MIDDLEWARE_CLASSES:

  File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 28, in 
__getattr__
self._import_settings()

  File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 55, in 
_import_settings
self._target = Settings(settings_module)

  File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 83, in 
__init__
raise EnvironmentError, "Could not import settings '%s' (Is it on sys.path? 
Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)

EnvironmentError: Could not import settings 'settings' (Is it on sys.path? Does 
it have syntax errors?): No module named settings



--~--~-~--~~~---~--~~
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: [newbie]Apache Deployment Problem

2008-02-07 Thread Tony Winslow
Kenneth Gonsalves wrote:
> On 06-Feb-08, at 7:41 PM, Tony Winslow wrote:
>
>   
>> I installed mod_python and do the configurations as the tutorial on  
>> the
>> official site. But mod_python still can not find the mysite.settings
>> module. What might be the problem?
>> 
>
> paste the relevant part of your apache config
>
>   

  SetHandler python-program
  PythonHandler django.core.handlers.modpython
  SetEnv DJANGO_SETTINGS_MODULE mysite.settings
  PythonDebug On
  PythonPath "sys.path + ['/path/to/mysite', '/var/www']"



I've tried many ways:
put settings.py with the other source codes,
set DJANGO_SETTINGS_MODULE to be settings or mysite.settings

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



django error about syncdb

2008-05-30 Thread tony yu

when I use syncdb, get the error:

[EMAIL PROTECTED] /data/mysite]# python manage.py syncdb
Error: One or more models did not validate:
auth.group: "admin.list_display" refers to '__ipow__', which isn't an
attribute, method or property.

pls help me, thanks!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django error about syncdb

2008-05-30 Thread tony yu

version info:
django svn version, freebsd 7.0, python 2.5.2
settings.py:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'mysite.polls',
)

the os stdout:
[EMAIL PROTECTED] /data/mysite]# python manage.py syncdb
Creating table auth_message
Creating table auth_group
Creating table auth_user
Creating table auth_permission
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Creating table polls_poll
Creating table polls_choice

You just installed Django's auth system, which means you don't have
any superusers defined.
Would you like to create one now? (yes/no): yes
Username (Leave blank to use 'root'): root
E-mail address: [EMAIL PROTECTED]
Password:
Password (again):
Superuser created successfully.
Installing index for auth.Message model
Installing index for auth.Permission model
Installing index for admin.LogEntry model
Installing index for polls.Choice model
Error: One or more models did not validate:
auth.group: "admin.list_display" refers to '__ipow__', which isn't an
attribute, method or property.

Karen, thank you.

On 5月30日, 下午9时22分, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Fri, May 30, 2008 at 4:55 AM, tony yu <[EMAIL PROTECTED]> wrote:
>
> > when I use syncdb, get the error:
>
> > [EMAIL PROTECTED] /data/mysite]# python manage.py syncdb
> > Error: One or more models did not validate:
> > auth.group: "admin.list_display" refers to '__ipow__', which isn't an
> >
attribute, method or property.
>
> > pls help me, thanks!
>
> What version of Django?
>
> What is the value for INSTALLED_APPS in your settings.py?
>
> If your INSTALLED_APPS includes 'django.contrib.auth', what happens when you
> remove it and try 'python manage.py syncdb' again?
>
> Karen
--~--~-~--~~~---~--~~
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 error about syncdb

2008-06-01 Thread tony yu

when i remove django.contrib.admin from INSTALLED_APPS, run syncdb
success.
I think django is not Compatible with python 2.5.2?

On 6月1日, 上午5时42分, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Sat, May 31, 2008 at 2:07 AM, tony yu <[EMAIL PROTECTED]> wrote:
>
> > version info:
> > django svn version, freebsd 7.0, python 2.5.2
> > settings.py:
> > INSTALLED_APPS = (
> >'django.contrib.auth',
> >'django.contrib.contenttypes',
> >'django.contrib.sessions',
> >'django.contrib.sites',
> >'django.contrib.admin',
> >'mysite.polls',
> > )
>
> > the os stdout:
> > [EMAIL PROTECTED] /data/mysite]# python manage.py syncdb
> > Creating table auth_message
> > Creating table auth_group
> > Creating table auth_user
> > Creating table auth_permission
> > Creating table django_content_type
> > Creating table django_session
> > Creating table django_site
> > Creating table django_admin_log
> > Creating table polls_poll
> > Creating table polls_choice
>
> > You just installed Django's auth system, which means you don't have
> > any superusers defined.
> > Would you like to create one now? (yes/no): yes
> > Username (Leave blank to use 'root'): root
> > E-mail address: [EMAIL PROTECTED]
> > Password:
> > Password (again):
> > Superuser created successfully.
> > Installing index for auth.Message model
> > Installing index for auth.Permission model
> > Installing index for admin.LogEntry model
> > Installing index for polls.Choice model
> > Error: One or more models did not validate:
> > auth.group: "admin.list_display" refers to '__ipow__', which isn't an
> > attribute, method or property.
>
> That's bizarre.  Model validation succeeds once, the tables are added and
> indices are created, then when syncdb goes to try and load fixtures it runs
> model validation again and this time it dies.
>
> I assume you have not changed anything in the django/contrib/auth/models.py
> file?
>
> Did this happen the very first time you ran syncdb or not until you added
> something (django.contrib.admin, mysite.polls)?  If you try removing
> mysite.polls from INSTALLED_APPS does the problem go away?  If it does, then
> the problem is somewhere in what you've done with mysite/polls, though I
> have no idea what.
>
> Karen
>
>
>
> > Karen, thank you.
>
> > On 5月30日, 下午9时22分, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> > > On Fri, May 30, 2008 at 4:55 AM, tony yu <[EMAIL PROTECTED]> wrote:
>
> > > > when I use syncdb, get the error:
>
> > > > [EMAIL PROTECTED] /data/mysite]# python manage.py syncdb
> > > > Error: One or more models did not validate:
> > > > auth.group: "admin.list_display" refers to '__ipow__', which isn't an
>
> > attribute, method or property.
>
> > > > pls help me, thanks!
>
> > > What version of Django?
>
> > > What is the value for INSTALLED_APPS in your settings.py?
>
> > > If your INSTALLED_APPS includes 'django.contrib.auth', what happens when
> > you
> > > remove it and try 'python manage.py syncdb' again?
>
> > > Karen
--~--~-~--~~~---~--~~
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: security of django.views.static.serve

2007-04-01 Thread Tony Maher

Malcolm Tredinnick wrote:
> On Sun, 2007-04-01 at 19:34 -0700, tonym wrote:
> 
>>Hello
>>
>>in http://www.djangoproject.com/documentation/static_files/ it states
>>
>>  With that said, Django does support static files during
>>development.
>>  Use  the view django.views.static.serve to serve media files.
>>  The big, fat disclaimer
>>  Using this method is inefficient and insecure. Do not use this in
>>a
>>  production setting. Use this only for development.
>>
>>I can understand why it is inefficient but why is it insecure?
> 
> 
> It's never been audited for security. We also don't want to make the
> commitment that even if it is secure today it won't become accidentally
> insecure tomorrow due to some code change.

Ah ok.

>>For our application where there are few statics files, just css,
>>images. Setting up a separate  media server (as described in
>>http://www.djangoproject.com/documentation/modpython/#serving-media-files)
>>is extra complexity that we would like to avoid.
> 
> You don't need to set up a separate server if you don't have lots of
> static media to server (or really high volumes on the dynamic side).
> However, let your webserver serve the static content directly: don't go
> through Django. Webservers are very good at serving static content, so
> Django doesn't have to be.
> In Apache, for example, this means putting in a Directory or Location
> directive (normally a Directory) that specifies where to retrieve files
> from for a particular URL prefix. This is just like you would do for
> normal static files, nothing Django-specific here.

This is what we have done.  While it is just  another config line it makes
it just that little bit harder for someone new to follow what has been done.

Thanks for the prompt response.

--
tonym

--~--~-~--~~~---~--~~
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: Looking for experienced Django backend engineer

2022-07-02 Thread Tony Wong
Yes. Please
Good dev is always needed

Tony

On Sat, Jul 2, 2022 at 3:23 PM Sunday Ajayi  wrote:

> Hi Tony,
>
> Apologies for the late response.
> But if you still need a dev, I can still share my resume with you.
> Regards
> *AJAYI Sunday *
> (+234) 806 771 5394
> *sunnexaj...@gmail.com *
>
>
>
> On Fri, Feb 25, 2022 at 1:06 AM anderso...@gmail.com <
> anderson.wan...@gmail.com> wrote:
>
>> the domain name we bought is : datamall DOT ai.
>> In short, it help AI company to collect data they need ,and users get
>> paid for submitting the data.
>>
>> We treat all user uploaded data as NFT, thus we are also building our
>> public blockchain, but it might be centralized. Just like E-CNY, but we
>> plan to open all transaction history.
>>
>> Best wishes.
>> Tony
>>
>>
>> On Thursday, February 24, 2022 at 8:34:50 AM UTC-8 sunne...@gmail.com
>> wrote:
>>
>>> Hi Tony,
>>>
>>> You can share a mail of what the project is about. I may be interested.
>>>
>>> Regards
>>> *AJAYI Sunday *
>>> (+234) 806 771 5394 <+234%20806%20771%205394>
>>> *sunne...@gmail.com*
>>>
>>>
>>>
>>> On Thu, Feb 24, 2022 at 3:05 PM anderso...@gmail.com <
>>> anderso...@gmail.com> wrote:
>>>
>>>> Dear all,
>>>>
>>>> I'm a SDE, trying to start a startup company.
>>>> Since I learned Django before, so, I plan to use Django to build the
>>>> backend.
>>>>
>>>> But still, we need an backend engineer for our server.
>>>> Ping me if you are interestd.
>>>>
>>>> You can consider this as both freelancer, and stock if it is a good
>>>> match.
>>>>
>>>> Please send me your Resume.
>>>>
>>>> Best wishes.
>>>>
>>>> Tony Wong
>>>>
>>>> --
>>>> 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 view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/f13e6f81-8490-4418-9d38-ad14ba17790fn%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/django-users/f13e6f81-8490-4418-9d38-ad14ba17790fn%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/f9dd0af2-8917-4379-8dec-0a583db3605cn%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/f9dd0af2-8917-4379-8dec-0a583db3605cn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/veFA7lPluGg/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CAKYSAw3S%3D_pgQcdq9ZN1Ho1AhNi_z1N83aUFbRhwdrM45uyXUA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAKYSAw3S%3D_pgQcdq9ZN1Ho1AhNi_z1N83aUFbRhwdrM45uyXUA%40mail.gmail.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/CAJkRgPc39kxCQdaewokTLLR52iq3Gj_gkqtHw%2BmPufcwUrtfNA%40mail.gmail.com.


Re: Looking for experienced Django backend engineer

2022-07-02 Thread Tony Wong
>
>
> no part time considered,

sorry

-- 
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/CAJkRgPfe73X91hzkjKJG%3DoB0q1cewvrpnks9yJZ8W%3DTB0%3D3iPA%40mail.gmail.com.


Re: Looking for experienced Django backend engineer

2022-07-03 Thread Tony Wong
Just forward to my teammate.
Good luck

On Sun, Jul 3, 2022 at 2:04 PM Mohammad Foysal  wrote:

>
> I have been working with python for the last two years. so I feel that I
> have some transferable skills to the position you are looking for. As a web
> application developer I have professional experience in various concepts of
> design and development.
>
> Please find enclosed my CV if you have any questions about my skills and
> experiences.
>
> Thank you for your time and consideration and I look forward to hearing
> from you soon.
>
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/veFA7lPluGg/unsubscribe.
> To unsubscribe from this group and all its topics, 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/529F41A5-EF89-437E-9DEF-5A1F6909811C%40gmail.com
> 
> .
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/veFA7lPluGg/unsubscribe.
> To unsubscribe from this group and all its topics, 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/529F41A5-EF89-437E-9DEF-5A1F6909811C%40gmail.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/CAJkRgPcO0jFp1hGWm1B763DyG4FWki5d43oYUz2m1%3DrtAzOA_w%40mail.gmail.com.


Can't get pagination to work in django.!!!

2012-02-28 Thread Tony Kyriakides
I get this error:

Template error

In template /home/tony/Documents/vidupdate/templates/index.html, error
at line 24

Caught TypeError while rendering: 'Page' object is not iterable
14  {% else %}
15  Register
16  Login
17  {% endif %}
18  feedback
19  Contact
20  
21  
22  Entries
23  
24  {% for entry in entries %}
25  {{ entry.title }}
{{ entry.posted }} {{ entry.submitter }}
26  {% endfor %}
27  
28
29  
30  {% if entries.object_list and posts.paginator.num_pages > 1 %}
31  
32  
33  {% if entries.has_previous %}
34  previous

this is my view:

from django.shortcuts import render_to_response
from vidupdate.posts.models import Entry
from django.template import RequestContext
from django.core.paginator import Paginator, InvalidPage, EmptyPage

def homepage(request):
entries = Entry.objects.all().order_by('-posted')
paginator = Paginator(entries, 2)

try: page = int(request.GET.get('page', '1'))
except ValueError: page = 1

try:
entries = paginator.page(page)
except (InvalidPage, EmptyPage):
entries = paginator.page(paginator.num_pages)

return render_to_response('index.html', {'entries' : entries},
context_instance=RequestContext(request))

this is in my template:

{% for entry in entries %}
{{ entry.title }}
{{ entry.posted }} {{ entry.submitter }}
{% endfor %}




{% if contacts.has_previous %}
previous
{% endif %}


Page {{ contacts.number }} of
{{ contacts.paginator.num_pages }}.


{% if contacts.has_next %}
next
{% endif %}



-- 
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: Can't get pagination to work in django.!!!

2012-02-28 Thread Tony Kyriakides
hey tom its still not working :P it was easier for me to copy it from
the docs...i still get the same error

template:
Entries

{% for entry in entries %}
{{ entry.title }}
{{ entry.posted }} {{ entry.submitter }}
{% endfor %}



{% if entries.has_previous %}
previous
{% endif %}


Page {{ entries.number }} of
{{ entries.paginator.num_pages }}.


{% if entries.has_next %}
next
{% endif %}


On Feb 28, 5:01 pm, Tom Evans  wrote:
> On Tue, Feb 28, 2012 at 2:45 PM, Tony Kyriakides
>
>
>
>
>
>
>
>
>
>  wrote:
> > I get this error:
>
> > Template error
>
> > In template /home/tony/Documents/vidupdate/templates/index.html, error
> > at line 24
>
> > Caught TypeError while rendering: 'Page' object is not iterable
> > 14      {% else %}
> > 15      Register
> > 16      Login
> > 17      {% endif %}
> > 18      feedback
> > 19      Contact
> > 20      
> > 21      
> > 22      Entries
> > 23      
> > 24      {% for entry in entries %}
> > 25      {{ entry.title }}
> > {{ entry.posted }} {{ entry.submitter }}
> > 26      {% endfor %}
>
> https://docs.djangoproject.com/en/1.3/topics/pagination/#using-pagina...
>
> Compare and contrast what you are doing with 'entries' in that for
> loop and what the docs do with the equivalent object in the linked
> example, 'contacts'.
>
> Your pagination links are referring to 'contacts' rather than
> 'entries' - copy/paste error there?
>
> Cheers
>
> Tom

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



Re: Can't get pagination to work in django.!!!

2012-02-28 Thread Tony Kyriakides
Sorry tom! Thanks a lot mate you just made my day!

On Feb 28, 5:34 pm, Tom Evans  wrote:
> Hi. Re-read what I said:
>
> > 24      {% for entry in entries %}
>
>            ^^^
>
> > 25      {{ entry.title }}
> > {{ entry.posted }} {{ entry.submitter }}
> > 26      {% endfor %}
>
> Compare and contrast what you are doing with 'entries' in that for
> loop and what the docs do with the equivalent object in the linked
> example, 'contacts'.
>
> This is the part of the docs I linked you to:
>
> {% for contact in contacts.object_list %}
>     {# Each "contact" is a Contact model object. #}
>     {{ contact.full_name|upper }}
>     ...
> {% endfor %}
>
> Any clearer?
>
> Cheers
>
> Tom

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



How can I use order_by and filter at the same time? (drives me nuts..!!!)

2012-03-01 Thread Tony Kyriakides
How can I use order_by and filter at the same time? (drives me
nuts..!!!)

This is what i tried:

from django.shortcuts import render_to_response
from vidupdate.posts.models import Entry
from datetime import datetime  #( I even imported the date only)


def entry_view(request):
entries = Entry.objects.all().filter(posted.date ==
today).order_by('pushes')

def entry_view(request):
entries =
Entry.objects.all().filter(date.today()).order_by('pushes')

def entry_view(request):
entries =
Entry.objects.all().filter(datetime.date.today()).order_by('pushes')


I think I am wrong at the .filter()...
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: How can I use order_by and filter at the same time? (drives me nuts..!!!)

2012-03-01 Thread Tony Kyriakides
Tom thanks again for helping :)

On Thursday, March 1, 2012 3:21:41 PM UTC+2, Tony Kyriakides wrote:
>
> How can I use order_by and filter at the same time? (drives me 
> nuts..!!!) 
>
> This is what i tried: 
>
> from django.shortcuts import render_to_response 
> from vidupdate.posts.models import Entry 
> from datetime import datetime  #( I even imported the date only) 
>
>
> def entry_view(request): 
> entries = Entry.objects.all().filter(posted.date == 
> today).order_by('pushes') 
>
> def entry_view(request): 
> entries = 
> Entry.objects.all().filter(date.today()).order_by('pushes') 
>
> def entry_view(request): 
> entries = 
> Entry.objects.all().filter(datetime.date.today()).order_by('pushes') 
>
>
> I think I am wrong at the .filter()... 
> Thanks in advance..!!


On Thursday, March 1, 2012 3:21:41 PM UTC+2, Tony Kyriakides wrote:
>
> How can I use order_by and filter at the same time? (drives me 
> nuts..!!!) 
>
> This is what i tried: 
>
> from django.shortcuts import render_to_response 
> from vidupdate.posts.models import Entry 
> from datetime import datetime  #( I even imported the date only) 
>
>
> def entry_view(request): 
> entries = Entry.objects.all().filter(posted.date == 
> today).order_by('pushes') 
>
> def entry_view(request): 
> entries = 
> Entry.objects.all().filter(date.today()).order_by('pushes') 
>
> def entry_view(request): 
> entries = 
> Entry.objects.all().filter(datetime.date.today()).order_by('pushes') 
>
>
> I think I am wrong at the .filter()... 
> Thanks in advance..!!


On Thursday, March 1, 2012 3:21:41 PM UTC+2, Tony Kyriakides wrote:
>
> How can I use order_by and filter at the same time? (drives me 
> nuts..!!!) 
>
> This is what i tried: 
>
> from django.shortcuts import render_to_response 
> from vidupdate.posts.models import Entry 
> from datetime import datetime  #( I even imported the date only) 
>
>
> def entry_view(request): 
> entries = Entry.objects.all().filter(posted.date == 
> today).order_by('pushes') 
>
> def entry_view(request): 
> entries = 
> Entry.objects.all().filter(date.today()).order_by('pushes') 
>
> def entry_view(request): 
> entries = 
> Entry.objects.all().filter(datetime.date.today()).order_by('pushes') 
>
>
> I think I am wrong at the .filter()... 
> Thanks in advance..!!


On Thursday, March 1, 2012 3:21:41 PM UTC+2, Tony Kyriakides wrote:
>
> How can I use order_by and filter at the same time? (drives me 
> nuts..!!!) 
>
> This is what i tried: 
>
> from django.shortcuts import render_to_response 
> from vidupdate.posts.models import Entry 
> from datetime import datetime  #( I even imported the date only) 
>
>
> def entry_view(request): 
> entries = Entry.objects.all().filter(posted.date == 
> today).order_by('pushes') 
>
> def entry_view(request): 
> entries = 
> Entry.objects.all().filter(date.today()).order_by('pushes') 
>
> def entry_view(request): 
> entries = 
> Entry.objects.all().filter(datetime.date.today()).order_by('pushes') 
>
>
> I think I am wrong at the .filter()... 
> Thanks in advance..!!

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



how to emulate parallel multi-user usability testing with django and selenium/grid?

2012-04-24 Thread Tony Schmidt


I can get my Selenium tests running fine for one user/ sequentially on 
Django 1.4 using 
LiveServerTestCase,
 
but I would like to emulate parallel multi-user testing. I don't think I 
need real load testing, since my apps are mostly moderate/low traffic 
web-sites and internal web-apps, so I would prefer to avoid extra tools 
like JMeter.

I've started out setting up Selenium Grid 
but 
am not sure how to keep my tests independent and still run multiple tests 
with multiple users. I assume the test cases should be run for different 
users on the same DB simultaneously - but each test drops and creates a new 
DB, so I don't understand how that is possible.

And I don't want to sign up for a service like 
BrowserMob
.

-- 
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/-/hNtxu6iloTAJ.
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 Gig - Sacramento/Bay Area, CA] Help make Django/FOSS a success for independent/local grocery retail

2012-05-25 Thread Tony Schmidt
I can read this list and the docs all I want, but there's no substitute for 
experienced code review and pair programming.

*So we, the Sacramento Natural Foods Co-op, are seeking a (preferably 
local) Django guru to help bring best practices to our in-house software 
development.

We have a small I.T. department with one full-time developer and are trying 
to liberate our internal systems using Free Software and Python/Django.  As 
a co-operative, we believe in local/community investment and sharing, which 
is why we are trying to empower in-house staff with custom software and 
tools.  We also hope to share our software with the broader grocery retail 
industry, at some point.  

We have been using Django for about a year for two projects, and are about 
to start a third.  We need someone to help provide support to our in-house 
developer 5-15 hours per week through on-site or remote pair programming 
and other means of collaboration to insure that we are building the best 
Django apps possible.

The current project we need support for is scheduled for a three month time 
frame, starting immediately.  We figure you probably need about 3+ years 
Django experience and some sample code/ sites/ apps to qualify as a “guru” 
- so please have that available.  Please contact tschmidt at our domain, 
sacfoodcoop, which uses the popular “com” TLD, if interested.* 

-- 
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/-/5brCoFsmXvkJ.
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.



should Django groups and permissions be hard-coded or bootstrapped?

2012-10-25 Thread Tony Schmidt


I'm building an app that assumes the existence of certain groups and 
permissions for its workflow. For example, a "member" can log into the app 
and view and edit their personal data, but cannot see notes that would 
typically be displayed on the same screen. An "employee" can see those 
notes and create or edit their own, but only a "member manager" can delete 
or edit anyone's notes.

My issue is with bootstrapping the data for this app. I can create JSON 
fixture data for the groups, but then I have to hard-code the PKs, which 
seems like bad practice (what if a third party app I wanted to use did the 
same thing and there was a conflict?) A bigger issue is the permissions - I 
would have to add PKs to the permissions which in turn would have PKs to 
their content types.

I've read about using the post_syncdb hook to add initial data in a more 
programmatic fashion which I'm hoping will help me resolve the hard-coded 
PK issue. But I'm wondering whether this is the best solution to this 
problem, or if I'm "abusing" the Django Group and Permission concepts, 
here, and should be doing something else, like creating new models or just 
putting flags (like "is_member_manager") on my user profile model, etc.

-- 
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/-/lzhz-lJSPlcJ.
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.



why can't I access a dictionary with an initial form field value from my django template?

2011-08-23 Thread Tony Schmidt
I thought this should be the proper syntax in my template:

{{ MYDICT.myform.somefield.value }}

But I get a "can't parse remainder error."

Just putting {{ myform.somefield.value }} gives me "3" and {{ MYDICT.
3 }} gives me the dictionary value I want.

Am I missing something?

-- 
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: why can't I access a dictionary with an initial form field value from my django template?

2011-08-23 Thread Tony Schmidt
Thanks, Reinout.

I wound up creating a custom "getter" filter so I could do {{ MYDICT|
get:myform.somefiled.value }} - which I'm surprised isn't a built-in,
actually.  But I think your suggestion is a good alternative.

Tony

On Aug 23, 1:40 pm, Reinout van Rees  wrote:
> On 23-08-11 21:16, Tony Schmidt wrote:
>
> > I thought this should be the proper syntax in my template:
>
> > {{ MYDICT.myform.somefield.value }}
>
> > But I get a "can't parse remainder error."
>
> > Just putting {{ myform.somefield.value }} gives me "3" and {{ MYDICT.
> > 3 }} gives me the dictionary value I want.
>
> > Am I missing something?
>
> MYDICT.myform looks up an 'myform' attribute on MYDICT or the 'myform'
> key in the MYDICT dictionary. Which doesn't exist.
>
> There's no way the template language can know that it first has to look
> up the last three items and then apply that to the first item. That's
> the basic problem.
>
> Best solution probably: just do the MYDICT[myform.somefield.value] in
> your view and pass the value to the template?
>
> Reinout
>
> --
> Reinout van Rees                    http://reinout.vanrees.org/
> rein...@vanrees.org            http://www.nelen-schuurmans.nl/
> "If you're not sure what to do, make something. -- Paul Graham"

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



Will template extends break the html structure?

2011-10-19 Thread Tony Guo
Hi,everyone.I have had a strange problem on my homework .I load
"index.html" template,which extends "base.html" template,in views,then
access it through firefox and firebug show that the  markup
seems to be broke.However,if loading "base.html" directly instead of
"index.html" in views,it works right.My English is not good and I
can't sure if you are able to understand ,so,they are my project files
(including "views.py","template/base.html","template/index.html")
following and you can test it if you like.
Thank you.

##[views.py]
#-*- coding: utf-8 -*-
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.template.loader import get_template
import copy
import  time
BaseDic={
'NowTime':time.asctime(),
}
def index(request):
dic = copy.deepcopy(BaseDic)
dic = RequestContext(request,dic)
return render_to_response('index.html',dic)
###[file end]###


{% extends "base.html"%}









{% block HEAD %}PQP Interview System{% endblock %}


This is BODY




-- 
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: Will template extends break the html structure?

2011-10-19 Thread Tony Guo
It's OK now.The source code is right,but,for using some Chinese
character,i have to change the source file from GB2312 to UTF-8(in
win7) during which something go wrong and caused such a error.I am
using Ubuntu now and everything goes right.

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



how to only allow google apps auth from one domain

2012-01-09 Thread Tony Schmidt
I tried django-social-auth and googleappsauth but both allow me to
authenticate from any domain.  Has anybody had luck setting this up
with these, or any other packages?

-- 
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 only allow google apps auth from one domain

2012-01-10 Thread Tony Schmidt
Got it: Hacked the django-social-auth Google back-end to filter by
domain.  I'll see if the project wants to accept my changes as a
setting.

On Jan 9, 5:38 pm, Tony Schmidt  wrote:
> I tried django-social-authand googleappsauth but both allow me to
> authenticate from anydomain.  Has anybody had luck setting this up
> with these, or any other packages?

-- 
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: imagefiled don't Work

2012-01-27 Thread Tony Kyriakides
(in the terminal)
python manage.py syncdb

On Jan 21, 8:57 am, cha  wrote:
> Hello I reading this 
> tutorialhttps://pype.its.utexas.edu/docs/tutorial/unit6.html#answers
> it's work OK But When I want improve it and add ImageField in Category
> Model i have problem with ImageField It's Not uploaded
>
> file = models.ImageField(upload_to='img/%Y')
>
> see code please :
> _
> views.py
> _
> from django import forms
> class CategoryForm(forms.ModelForm):
>     class Meta:
>         model = Category
>
> def add_category(request):
>     if request.method == "POST":
>         form = CategoryForm(request.POST, request.FILES)
>         ## Handle AJAX  ##
>         if request.is_ajax():
>             if form.is_valid():
>                 form.save()
>                 # Get a list of Categories to return
>                 cats = Category.objects.all().order_by('name')
>                 # Create a dictionary for our response data
>                 data = {
>                     'error': False,
>                     'message': 'Category %s Added Successfully' %
> form.cleaned_data['name'],
>                     # Pass a list of the 'name' attribute from each
> Category.
>                     # Django model instances are not serializable
>                     'categories': [c.name for c in cats],
>                 }
>             else:
>                 # Form was not valid, get the errors from the form and
>                 # create a dictionary for our error response.
>                 data = {
>                     'error': True,
>                     'message': "Please try again! one",
>                     'name_error': str(form.errors.get('name', '')),
>                     'slug_error': str(form.errors.get('slug', '')),
>                     'file_error': str(form.errors.get('file', '')),
>                 }
>             # encode the data as a json object and return it
>             return http.HttpResponse(json.dumps(data))
>
>         ## Old Form Handler Logic ##
>         if form.is_valid():
>             form.save()
>             return http.HttpResponseRedirect('/category/')
>     else:
>         form = CategoryForm()
>     cats = Category.objects.all().order_by('name')
>     context = Context({'title': 'Add Category', 'form': form,
> 'categories': cats})
>     return render_to_response('ajax_form.html',
> context,context_instance=RequestContext(request))
>
> ___
> ajax_form.html
> ___
>
>      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
> http://www.w3.org/1999/xhtml";>
> 
>    {{ title }}
>    
>       #message {width:250px; background-color:#aaa;}
>       .hide {display: none;}
>    
>    http://ajax.googleapis.com/ajax/
> libs/jquery/1.3.2/jquery.js">
> 
> 
>
>     
>     // prepare the form when the DOM is ready
>     $(document).ready(function() {
>         $("#add_cat").ajaxStart(function() {
>             // Remove any errors/messages and fade the form.
>             $(".form_row").removeClass('errors');
>             $(".form_row_errors").html('');
>             $("#add_cat").fadeTo('slow', 0.33);
>             $("#add_cat_btn").attr('disabled', 'disabled');
>             $("#message").addClass('hide');
>         });
>
>         // Submit the form with ajax.
>         $("#add_cat").submit(function(){
>             $.post(
>                 // Grab the action url from the form.
>                 "#add_cat.getAttribute('action')",
>
>                 // Serialize the form data to send.
>                 $("#add_cat").serialize(),
>
>                 // Callback function to handle the response from view.
>                 function(resp, testStatus) {
>                     if (resp.error) {
>                         // check for field errors
>                         if (resp.name_error != '') {
>                             $("#name_row").addClass('errors');
>                             $("#name_errors").html(resp.name_error);
>                         }
>                         if (resp.slug_error != '') {
>                             $("#slug_row").addClass('errors');
>                             $("#slug_errors").html(resp.slug_error);
>                         }
>                         if (resp.file_error != '') {
>                             $("#file_row").addClass('errors');
>                             $("#file_errors").html(resp.file_error);
>                         }
>                     } else {
>                         // No errors. Rewrite the category list.
>                         $("#categories").fadeTo('fast', 0);
>                         var text = new String();
>                         for(i=0; i                             var m = resp.categories[i]
>                             text += "
  • " + m + "
  • " >                         } >                         $("#categories").html(text); >                         $("#categories").fadeTo('slow', 1); >                         $("#id_name").attr('valu

    Template Loader Error: (It's been really frustrating till now..!)

    2012-01-27 Thread Tony Kyriakides
    Hey all...  i get this error while i have a template directory and my
    about.html file It doesn't display the home.html either...
    
    Environment:
    
    
    Request Method: GET
    Request URL: http://127.0.0.1:8000/about/
    
    Django Version: 1.3.1
    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']
    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')
    
    Template Loader Error:
    Django tried loading these templates, in this order:
    Using loader django.template.loaders.filesystem.Loader:
    /home/tony/Documents/blog/blog/templates/about.html (File does not
    exist)
    Using loader django.template.loaders.app_directories.Loader:
    
    
    
    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 "/home/tony/Documents/blog/../blog/views.py" in about
      9. return render_to_response('about.html',)
    File "/usr/local/lib/python2.7/dist-packages/django/shortcuts/
    __init__.py" in render_to_response
      20. return HttpResponse(loader.render_to_string(*args,
    **kwargs), **httpresponse_kwargs)
    File "/usr/local/lib/python2.7/dist-packages/django/template/
    loader.py" in render_to_string
      181. t = get_template(template_name)
    File "/usr/local/lib/python2.7/dist-packages/django/template/
    loader.py" in get_template
      157. template, origin = find_template(template_name)
    File "/usr/local/lib/python2.7/dist-packages/django/template/
    loader.py" in find_template
      138. raise TemplateDoesNotExist(name)
    
    Exception Type: TemplateDoesNotExist at /about/
    Exception Value: about.html
    
    -- 
    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.
    
    
    

    newbie- delete confirmation

    2013-05-16 Thread tony gair
    
    I'm making a cbv with django braces
    
    I'm wanting to delete a record with a confirm form , does anyone know of an 
    exampple to show me how to 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 http://groups.google.com/group/django-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
    
    
    
    

    listing objects in a html file

    2013-05-28 Thread tony gair
    
    
    This file is used to print out the name of the premises with an update link 
    , however I wanted to add a list of premises with the in_use flag set to 
    false. 
    Can anyone tell me what I am doing wrong?
    
    
    {% extends "base.html" %}
    
    {% block content %}
    Premises
    
    {% unusedpremises = [] %}
    {% for premises in object_list %}
    {% if premises.in_use %}
    {{ premises.name }}  Update   
     
    {% else unusedpremises.add(premises) %}
    {% endif %}
    {% endfor %}
    
    Unused Premises
    
    {% for premises in unusedpremises %}
    {{ premises.name }}  Update  
    %nbsp 
    {% endif %}
    {% endfor %}
    
    {% endblock %}
    
    -- 
    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.
    
    
    
    

    linking the logged in user to other models to filter query sets -( noobie )

    2013-05-29 Thread tony gair
    
    
    I've done a basic django app with a user which contains an organisation and 
    premises foreign key inside the user model which has been inherited using 
    the features of django 1.5.
    
    I use the organisation id and premises id inside other models which I would 
    like to present themselves providing they are the same.
    
    I have tried to closely follow the 'two scoops of django approach' in that 
    I use a CBV with django braces approach to show my models.
    
    It is very important for me only to show the models in the views which use 
    either the organisation id or premises id.
    
    At the moment in my  forms.py for my  user it looks like
    
    
    #forms.py
    class HeatingUserForm ( forms.ModelForm):
    
    premises = CustomModelChoiceField(queryset=Premises.objects.all())
    organisation = CustomModelChoiceField(queryset=Organisation.objects.all())
    class Meta:
    model=Heating_User
    fields = [ 'username', 'password', 'first_name', 'last_name', 
    'email', 'is_staff', 'is_active', 'date_joined', 'jobtitle', 
    'organisation', 'premises' ]
    
    ***
    
    Unless the user is a super user, I want the organisation to be restricted 
    to the organisation that the logged in user is of the same . The premises 
    should be restricted to those premises that have the same id as the logged 
    in user. 
    
    Can anyone tell me how this is done?
    
    :)
    
    -- 
    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: linking the logged in user to other models to filter query sets -( noobie )

    2013-05-29 Thread tony gair
    I think my first post was a bit messy and I left some information out
    I have an organisation as a foreign key contained in my abstact user object 
    which is Heating_User. The premises also contains the organisation as a 
    foreign key. What I am looking to do on my premises view is to filter the 
    premises so that the organisation is the same as that for the logged in 
    user. Although my model does include the premises id I want it so there is 
    a organisation wide flag that would list all the premises if that flag was 
    set. The superuser flag I (oh my that looks really useful). I think you 
    have probably told me what I need to know but I'm not sure. I guess what I 
    am asking in addition is how do I access the logged in user organisation 
    foreign key so that I can filter the query? 
    
    I hope that makes sense, I am quite new to this, but very enthused!!
    
    On Wednesday, 29 May 2013 15:16:32 UTC, Tom Evans wrote:
    >
    > On Wed, May 29, 2013 at 3:29 PM, tony gair > 
    > wrote: 
    > > 
    > > 
    > > I've done a basic django app with a user which contains an organisation 
    > and 
    > > premises foreign key inside the user model which has been inherited 
    > using 
    > > the features of django 1.5. 
    > > 
    > > I use the organisation id and premises id inside other models which I 
    > would 
    > > like to present themselves providing they are the same. 
    > > 
    > > I have tried to closely follow the 'two scoops of django approach' in 
    > that I 
    > > use a CBV with django braces approach to show my models. 
    > > 
    > > It is very important for me only to show the models in the views which 
    > use 
    > > either the organisation id or premises id. 
    > > 
    > > At the moment in my  forms.py for my  user it looks like 
    > > 
    > >  
    > > #forms.py 
    > > class HeatingUserForm ( forms.ModelForm): 
    > > 
    > > premises = CustomModelChoiceField(queryset=Premises.objects.all()) 
    > > organisation = 
    > CustomModelChoiceField(queryset=Organisation.objects.all()) 
    > > class Meta: 
    > > model=Heating_User 
    > > fields = [ 'username', 'password', 'first_name', 'last_name', 
    > > 'email', 'is_staff', 'is_active', 'date_joined', 'jobtitle', 
    > 'organisation', 
    > > 'premises' ] 
    > > 
    > > *** 
    > > 
    > > Unless the user is a super user, I want the organisation to be 
    > restricted to 
    > > the organisation that the logged in user is of the same . The premises 
    > > should be restricted to those premises that have the same id as the 
    > logged 
    > > in user. 
    > > 
    > > Can anyone tell me how this is done? 
    > > 
    > > :) 
    > > 
    >
    > You want to do different things in the form based upon the current 
    > user, so the first step is to require that a user object is passed to 
    > the form's __init__ method. Then, you simply manipulate the queryset 
    > attributes on the desired fields after calling the super class' 
    > __init__ method. 
    >
    > Also, if premises and organisation are foreign key fields, as it 
    > seems, you don't need to declare the fields at all: 
    >
    > class HeatingUserForm (forms.ModelForm): 
    > def __init__(self, *args, **kwargs): 
    > self.user = kwargs.pop('user') 
    > super(HeatingUserForm, self).__init__(*args, **kwargs) 
    > if self.user.is_superuser: 
    > self.fields['premises'].queryset = Premises.objects.all() 
    > self.fields['organisation'].queryset = 
    > Organisation.objects.all() 
    > else: 
    > self.fields['premises'].queryset = 
    > Premises.objects.filter(users=self.user) 
    > self.fields['organisation'].queryset = 
    > Organisation.objects.filter(users=self.user) 
    > class Meta: 
    > model=Heating_User 
    > fields = [ … ] 
    >
    > You could also do some additional cleanup work, if the number of 
    > choices for either of those two fields is exactly one, you could 
    > replace the widget on the form field with a hidden input, so that you 
    > do not display a pointless control (OTOH, it may not be pointless). 
    >
    > Cheers 
    >
    > Tom 
    >
    
    -- 
    You received this message because you are subscribed to the Google Groups 
    "Django users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email 
    to django-users+unsubscr...@googlegroups.com.
    To post to this group, send email to django-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/django-users?hl=en.
    For more options, visit https://groups.google.com/groups/opt_out.
    
    
    
    

    django 1.5 abstractuser / accessing information of logged on user

    2013-05-30 Thread tony gair
    
    I am using CBV / django braces for authentication. My user authorisation 
    model inherits abstractuser and adds a few fields which are foreign keys to 
    two other models organisation and premises.
    
    When a form initialises I want to be able to examine the details of the 
    user logged in , look to see if they are a is_superuser  or is_staff and 
    occupy my organisation and premises form fields accordingly using the 
    values stored as foreign keys in the logged on and authenticated user. 
    
    My main problem at the moment is that I get a KeyError for the line 
    'self.user=kwargs.pop('user')' centered on 'user'
    
    
    #heating/forms.py
    from django import forms
    from .models import Organisation, Premises,  Heating_User, Room, Heater
    
    class HeatingUserForm ( forms.ModelForm):
    
      def __init__(self, *args, **kwargs):
    self.user=kwargs.pop('User')
    super(HeatingUserForm, self).__init__(*args, **kwargs)
    if self.user.is_superuser:
    self.fields['premises'].queryset = Premises.objects.all() 
    elif self.user.is_staff:
    self.fields['premises'].queryset = 
    Premises.objects.filter(organisation=self.user.organisation)
    else:
    self.fields['premises'].queryset = 
    Premises.objects.filter(id=self.user.premises)
     
    
    #models.py
    from django.conf import settings
    from django.core.urlresolvers import reverse
    from django.db import models
    from django.contrib.auth.models import AbstractUser
    
    class Heating_User (AbstractUser):
      jobtitle = models.CharField(max_length=255)
      organisation = models.ForeignKey(Organisation, null=True)
      premises = models.ForeignKey(Premises, null= True)
    def __unicode__(self):
    return self.username
    def get_absolute_url(self):
    return reverse('users-detail', kwargs={'pk':self.pk})
    #end of files
    
     
    can anyone see where I am going wrong 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 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.
    
    
    
    

      1   2   >