Absurdly long queries with Postgres 11 during unit tests

2021-06-07 Thread Rich Rauenzahn
This is heads up in case anyone sees something similar:

I have managed to trigger this degenerate query case in two completely 
different Django 2.2 projects.   In production with a normal sized dataset, 
the query time is fine.  But during unit testing with a small subset of the 
data, the queries took a long time.  A LONG time.

In the most recent case each query took 100x longer.  200+ seconds instead 
of 2 seconds.  The unit test dataset isn't very large because it's a unit 
test.  

I think I may have first seen this when I upgraded the project to postgres 
11.

Manually vacuuming between tests resolves the issue.  (Yes, autovacuum is 
on by default -- and isn't the db created from scratch for each 'manage 
test' invocation?)

This is how I did it:

def _vacuum():
# Some unit test queries seem to take a much longer time.
# Let's try vacuuming.
# https://stackoverflow.com/a/13955271/2077386
with connection.cursor() as cursor:
logger.info("Vacuum: begin")
cursor.execute("VACUUM ANALYZE")
logger.info("Vacuum: complete")

class VacuumMixin:
@classmethod
def setUpClass(cls):
_vacuum()
return super().setUpClass()

@classmethod
def tearDownClass(cls):
ret = super().tearDownClass()
_vacuum()
return ret

If anyone else sees this, please let me know.  Maybe we can further RCA it.



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e76b105e-ed53-4031-869c-830f94677ef4n%40googlegroups.com.


Influencing order of internal migration operations

2019-12-11 Thread Rich Rauenzahn
I've created a CompositeForeignKey constraint derived from Django's new 
BaseConstraint.  It requires that I manually make a unique_together in any 
of the referenced models views due to the DB internal requirements of 
composite foreign keys.

It mostly works -- except that when the operations are defined in the 
migration, the order is critical -- the unique_together's need to be made 
before the composite key SQL.

For now, I just went in and manually changed the order of operations in the 
migration to put the CompositeForeignKeys last.   Another way around would 
be to comment out all the CompositeForeignKey declarations in my models, 
migrate my unique_together's first, and then re-add the 
CompositeForeignKeys.

...I'm wondering if there is a supported way to hook into the migration 
creation process, give priorities to certain kinds of constraints, and then 
sort the operations by this priority before they are emitted into a 
migration.py.

Or any other ideas to make this a bit more seamless?

Rich

-- 
You received this message because you are subscribed 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/c5c30972-c5cb-402f-b88b-a072bb284318%40googlegroups.com.


Migrations appear to run twice when running tests

2019-11-19 Thread Rich Rauenzahn

I'm trying to figure out why my migrations appear to run twice when unit 
testing.I do have multiple dbs with custom routers to route to 
different databases.

I've tried debugging and tracing the routers to see if that's where the 
issue lies, but I don't know enough about the migration process to know 
what to look for.  

...I'm surprised it even works given that the database is already migrated 
once -- shouldn't the 2nd migrations fail?

I'm not expecting an answer -- I think there's not enough information.  

But where should I dig?

Rich


$ ./manage-coverage test --noinput -v 2
nosetests --logging-level=INFO --progressive-advisories --with-timer 
--timer-top-n=10 --with-prowl-report --with-timed-setup-report --with-id 
--id-file=/opt/gitlab-runner/NCiG8AGt/1/redacted-automation/reddash/djproj/.noseids
 
-v --verbosity=2
Using --with-id and --verbosity=2 or higher with nose-progressive causes 
visualization errors. Remove one or the other to avoid a mess.
Creating test database for alias 'default' ('reddash_cicd_3')...
Operations to perform:
  Synchronize unmigrated apps: api, bugzilla, celery, 
django_db_constraints, django_extensions, django_filters, django_nose, 
drf_yasg, humanize, messages, redauto, polymorphic, rest_framework, saml2, 
staticfiles, timezone_field
  Apply all migrations: accounts, admin, auth, contenttypes, dashboards, 
django_celery_beat, django_celery_results, reversion, sessions, tracking
Synchronizing apps without migrations:
  Creating tables...
Running deferred SQL...
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0001_initial... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying accounts.0001_initial... OK
  Applying tracking.0001_initial... OK
  Applying accounts.0002_auto_20160929_2021... OK
  Applying accounts.0003_auto_20190225_2216... OK
  Applying accounts.0004_token... OK
  Applying accounts.0005_auto_20190306_1804... OK
  Applying tracking.0002_apirequestlog_department... OK
  Applying accounts.0006_dedupe_20190422_1447... OK
  Applying accounts.0007_auto_20190422_1459... OK
  Applying accounts.0008_auto_20190730_2235... OK
  Applying accounts.0009_auto_20190802_1750... OK
  Applying accounts.0010_auto_20190906_0024... OK
  Applying accounts.0011_user_is_redauto... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying dashboards.0001_initial... OK
[...]
  Applying dashboards.0110_auto_20191118_1742... OK
  Applying django_celery_beat.0001_initial... OK
  Applying django_celery_beat.0002_auto_20161118_0346... OK
  Applying django_celery_beat.0003_auto_20161209_0049... OK
  Applying django_celery_beat.0004_auto_20170221_... OK
  Applying django_celery_beat.0005_add_solarschedule_events_choices... OK
  Applying django_celery_beat.0006_auto_20180210_1226... OK
  Applying django_celery_results.0001_initial... OK
  Applying reversion.0001_squashed_0004_auto_20160611_1202... OK
  Applying sessions.0001_initial... OK
  Applying tracking.0003_auto_20190822_1229... OK
  Applying tracking.0004_auto_20191030_2030... OK
  Applying tracking.0005_auto_20191030_2030... OK
  Applying tracking.0006_remove_apirequestlog_server_name... OK
  Applying tracking.0007_auto_20191030_2038... OK
Creating test database for alias 'bugzilla' (':memory:')...
Operations to perform:
  Synchronize unmigrated apps: api, bugzilla, celery, 
django_db_constraints, django_extensions, django_filters, django_nose, 
drf_yasg, humanize, messages, redauto, polymorphic, rest_framework, saml2, 
staticfiles, timezone_field
  Apply all migrations: accounts, admin, auth, contenttypes, dashboards, 
django_celery_beat, django_celery_results, reversion, sessions, tracking
Synchronizing apps without migrations:
  Creating tables...
Creating table bugs
Creating table bug_fix_by_map
Creating table products
Creating table phases
Creating table versions
Running deferred SQL...
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0001_initial... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying accounts.0001_initial... OK
  Applyi

Paginator UnorderedObjectListWarning on union(all=True) of two sorted queries

2019-04-16 Thread Rich Rauenzahn
I wonder if this is a case you want to catch and *not* warn about.

In my case, I'm doing a:

haves = 
MyModel.objects.filter(foreign_relationship=4).order_by('foreign_relationship__value',
 
'common_key')
havenots = MyModel.objects.exclude(id__in=haves).order_by('common_key')

query = haves.union(havenots, all=True)


And I'm using this with a Paginator.  The Paginator thinks the queries are 
not ordered, but they actually are (right?) due to the all=True in the 
union.

Is this a case the warning ought to handle and ignore?

The Django 1.11 source is:

def _check_object_list_is_ordered(self):
"""
Warn if self.object_list is unordered (typically a QuerySet).
"""
ordered = getattr(self.object_list, 'ordered', None)
if ordered is not None and not ordered:
obj_list_repr = (
'{} {}'.format(self.object_list.model, 
self.object_list.__class__.__name__)
if hasattr(self.object_list, 'model')
else '{!r}'.format(self.object_list)
)
warnings.warn(
'Pagination may yield inconsistent results with an 
unordered '
'object_list: {}.'.format(obj_list_repr),
UnorderedObjectListWarning,
stacklevel=3
)


Should I file a bug?

-- 
You received this message because you are subscribed 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/2d1dc6a6-35c1-48ac-afe3-d08cd4636990%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django template

2019-02-09 Thread rich gang
Hi guys,
I just finished learning python on sololeran.com.
And I wanna start django, so I was wondering If anybody would wanna help me
personally.
Like I said I have a fair knowledge about python.
I would be grateful.
thanks,

On Sat, 9 Feb 2019 at 11:43, PASCUAL Eric  wrote:

> Hi,
>
> Templates are nothing more than HTML files with special tags inside. In
> their simplest form, they can be plain HTML without any templating tags and
> they will thus be rendered without any change.
>
> In conclusion, to keep it simple and still let you the opportunity to
> benefit from templating features if ever the need arises in the future, let
> settings as they are and follow template view examples. The overhead will
> be minimal for such "static" templates since the engine provides a quite
> efficient preprocessing and caching mechanism and in any case,
> negligible compared to DB or network related stuff.
>
> Anyway, if for any reason you do not want to keep the templating engine in
> the path at all, your views can return basic HTTP responses containing
> static HTML data, either stored as constant strings in your code (not the
> cleanest option) or, better, as resources in your project (e.g. plain files
> somewhere they can be read from the app code).
>
> Best
>
> Eric
>
> --
> *From:* django-users@googlegroups.com  on
> behalf of Tom Zhang 
> *Sent:* Friday, February 8, 2019 19:59
> *To:* Django users
> *Subject:* Django template
>
> Hi,
>
> If I don't want to use any Django template and I just want to use regular
> html/javascript, how should I setup the template config in settings.py?
>
> Right now, my settings are:
>
> TEMPLATES = [
> {
> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
> 'DIRS': [os.path.join(BASE_DIR, 'templates')],
> 'APP_DIRS': True,
> 'OPTIONS': {
> 'context_processors': [
> 'django.template.context_processors.debug',
> 'django.template.context_processors.request',
> 'django.contrib.auth.context_processors.auth',
> 'django.contrib.messages.context_processors.messages',
> ],
> },
> },
> ]
>
> Thanks,
>
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e88d65e8-c992-4a57-ac5b-3ed5f60dab24%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/AM0P193MB03088A4EC2AEDE3EDCE2C2BE8C6A0%40AM0P193MB0308.EURP193.PROD.OUTLOOK.COM
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: multidb, don't create one of them during unit tests

2018-05-29 Thread Rich Rauenzahn
On Tuesday, May 29, 2018 at 12:09:46 PM UTC-7, Rich Rauenzahn wrote:
>
>
> Is this possible?  How?
>
>
Ah, found this thread which suggests just using sqlite locally... I'll give 
it a try:

https://groups.google.com/forum/#!topic/django-users/jxkTmibjmX4 

-- 
You received this message because you are subscribed 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/2fb17ad6-e3dc-4b35-a044-da24cb734413%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


multidb, don't create one of them during unit tests

2018-05-29 Thread Rich Rauenzahn
I'm using Django's (1.11) typical default db for my regular Django 
development, but I need to integrate with someone else's bugzilla db server 
running on mysql somewhere else (no web api available, mysql is the 
recommendation from them). So I've added a 2nd DB to my DB config 
pointing to their server.  I've used inspectdb to bring in their schema as 
models.

They have both a production instance and a test instance for reading bugs.  
These are both read only.

I'd like my unit tests to skip creating the test instance of their DB 
(since I'm not even running a mysql server to use, I don't have write 
access to theirs, and their test instance is already populated) and to just 
point my unit tests at their test instance.

I see I can override the TestRunner 

https://stackoverflow.com/questions/5917587/django-unit-tests-without-a-db

setup_databases in django.test.utils seems to take a global for keepdb so 
it doesn't seem like someone can choose on a per db basis ...

Is this possible?  How?

-- 
You received this message because you are subscribed 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/61d4c77e-2c5c-4afc-829d-3a1723d5cb2f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Designing templates for database application

2018-01-14 Thread rich
I've developed database applications before but this is my first attempt to 
use Django. I'm building a client management system for my own use and 
would like to see examples of templates for this purpose. It's not a blog 
or document-heavy app, but consists of tables (the schema's written) for 
companies, contacts, and other sales information. I've not before used 
grids or forms so these are new to me and having a template I can modify 
(or use for ideas) would be very helpful. Pointers appreciated.

Rich

-- 
You received this message because you are subscribed 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/3d529db6-3bb7-44d0-ba6d-d0a8ef2ab6bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Testing

2018-01-14 Thread Rich Shepard

  I've not received messages from this mail list since last summer. I now
have a need to communicate with others and learned that I'm still subscribed
so I want to learn if this message posts and is sent back to me by the MLM.

Rich

--
You received this message because you are subscribed 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/alpine.LNX.2.20.1801141304320.5312%40salmo.appl-ecosys.com.
For more options, visit https://groups.google.com/d/optout.


Constraints across foreign keys

2017-12-04 Thread Rich Rauenzahn

Let's say I have:

class Restaurant(Model):
   pass

class Table(Model)
   restaurant = ForeignKey(Restaurant)

class Chair(Model)
   restaurant = ForeignKey(Restaurant)
   table = ForeignKey(Table)

Is there a best practice for ensuring that the chair assigned to a table is 
always from the same restaurant?  These models above assume that we might 
have spare chairs not yet assigned to tables.

My actual case is more like this:

class A(Model):
   pass

class B(Model):
   a = ForeignKey(A)

class C(Model):
   a = ForeignKey(A)

class D(Model):
   b = ForeignKey(B)
   c = ForeignKey(C)

And I want to ensure b.a == c.a.

(I think I just have to manually add db sql constraints in my migrations 
and also override save())

Are there any well supported / used django packages to manage this for me?  
This https://github.com/rapilabs/django-db-constraints looks promising, but 
is awfully quiet.

Rich


-- 
You received this message because you are subscribed 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/eea28a8f-4a73-4f74-a182-d6ade68a6737%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Retroactively seting up virtualenv

2017-07-14 Thread Rich Shepard

  My business is not web site development and I'm starting development of a
django project for my own use. Django-1.11.3 is installed in
/usr/lib/python3.6/site-packages/django and my project is located in
/ ~/development/clientmgntsystem_project/.

  I had no issues the last time I ran 'python manage.py migrate' but today I
see that manage.py cannot find the installed django and asks if I have a
virtual environment. I do not because I have not seen my need for these.

  Rather than try to push water uphill, I'll install both virtualenv and
virtualenvwrapper using the SlackBuilds.org packages.

  My question is how to migrate both django and my project to the new
virtual environment.

Rich


Re: Defining project apps

2017-07-11 Thread Rich Shepard

On Tue, 11 Jul 2017, yingi keme wrote:


I don't think you will have any app conflicts if you give them names
applying to the content of the app or any other name that suites you best.


Yingi,

  I want to avoid Django reserved words if any exist. Both python and SQL
have reserved words so variables, classes, attributes, etc. do not use those
names. If Django has no issues with naming apps 'client_data' and 'reports'
I'll use those names because they clearly express their purpose.

Thanks,

Rich




Defining project apps

2017-07-11 Thread Rich Shepard

  My background is database applications, not web site, development so I
have started my first django-1.11.3 project by defining the database schema
and defining the classes in models.py. Now I want to define the app based on
this file and am not sure how to name it.

  This project is for my own use, a client relation management application
(which will go to github when done). I want to avoid name conflicts with app
names so my first inclination is to define one app as data and another as
reports.

  Please suggest appropriate app names if these would be problematic.

Rich


Re: The best database for django

2017-07-10 Thread Rich Shepard

On Mon, 10 Jul 2017, DEIBER ANDRES RINCON ROJAS wrote:


Hi to everybody, I'm developing an web application using Python and Django
and it requires storage of excel data, data volume high and still I don't
have a clear idea about what database manager implement, Could anyone help
me with some suggestions please?. Thanks for your time


  You can use any of the supported ones. Without knowing how "high" your
data volume is or will be, how many simultaneous users access the
application, nor the OS on which it runs I'll still recommend my favorite:
PostgreSQL. It's F/OSS, enterprise-class, suitable for a single user, and
has outstanding support on the maillists. I've used it for 20 years and am
now running version 9.6.3 for my own (and client) applications.

Rich


Re: First models.py needs tuning

2017-06-29 Thread Rich Shepard

On Thu, 29 Jun 2017, Guilherme Leal wrote:


"An iterable (e.g., a list or tuple) consisting itself of iterables of
exactly two items"

I don't think that constructing choices as a "iterableof 1 item iterables"
will work.

Think of each item in the choices iterables as a key-value pair, where the
first item is the key (literally is the value that is saved on the DB
field), and the value is the "display value".


Guilherme,

  I missed the first sentence when I looked at the page. Your third
paragraph explains the syntax very clearly. I'll change the code to comply.

Thanks very much,

Rich


Re: First models.py needs tuning

2017-06-29 Thread Rich Shepard

On Thu, 29 Jun 2017, Guilherme Leal wrote:


It wouldn't be the case to use the field choices?
https://docs.djangoproject.com/en/1.11/ref/models/fields/#django.db.models.Field.choices


Guilherme,

  Now that I know Field.choices exists it will certainly do the job.

  I read the example as translating a quoted string in two steps to a
two-character, uppercase abbreviation. Would the following one-step list of
choices be correct?

industry_choices (
('Agriculture'),
('Business, other'),
('Chemicals'),
('Energy'),
('Law'),
('Manufacturing'),
('Mining'),
('Municipalities'),
('Ports/Marine Services'),
('Transportation'),
)
industry=models.CharField(max_length=24, choices=industry_choices, 
default='Agriculture')

Thanks,

Rich




Re: First models.py needs tuning

2017-06-29 Thread Rich Shepard

On Wed, 19 Apr 2017, Mike Dewhirst wrote:


Second, I have a couple of fields with postgres check constraints; that
is, valid data is restricted to a list of strings. I've not found a
Django model field validator teaching me how to write this.



Use the model's clean() method ...
https://docs.djangoproject.com/en/1.11/ref/models/instances/#django.db.models.Model.clean


  What I see in Model.clean is a validation check which returns an error
message to the user if the check fails. I understand using this in cases
where required data are missing (such as the example of a draft article not
having a blank publication date). What I don't see is how to write a
validation check for an attribute whose value should be limited to a list.

  Example: a table attribute (column) for 'industry' in which valid entries
are limited to a list such as 'Agriculture', 'Business, other', 'Chemicals',
'Energy', 'Law').

  In postgres SQL this would be a constraint check. How do I write this in a
django Model.clean or its relatives?

Rich


Re: Pre-loading static data into database table

2017-06-29 Thread Rich Shepard

On Thu, 29 Jun 2017, John Thomas wrote:


419 is not that many. I'd probably do that via a Python shell. import
models.Cities for item in lists_of_lists_of_419 temp =
Cities(city+name=item[0], county_name=item[1]) temp.save()


John,

  I should have mentioned that the table does not currently exist in the
database. If the above is the preferred solution with an existing table,
then to add the table and date I can use the psql shell to read the file.

Thanks very much for clarifying,

Rich


Pre-loading static data into database table

2017-06-29 Thread Rich Shepard

  Reading
<https://docs.djangoproject.com/en/1.11/ref/migration-operations/#django.db.migrations.operations.RunSQL>
tells me that runSQL allows arbitrary SQL to run on the database ... except
for the postgres backend: "On most database backends (all but PostgreSQL),
Django will split the SQL into individual statements prior to executing
them."

  I want to insert data into the two columns of the database. The model
reads:

class Cities (models.Model):
city_name=models.CharField(max_length=24, unique=True)
county_name=models.CharField(max_length=12, unique=True)

and I have a list of 419 pairs of names I want to pre-load into this
database table. The rows contain the two variables; e.g.,
  Bend,Deschutes
  Birkenfeld,Columbia
  Blachly,Lane
  Black Butte Ranch,Deschutes

  So, using a postgres back end can I write,

  migrations.RunSQL("INSERT INTO Cities (city_name,county_name) VALUES
('Bend','Dechutes');")

repeated for each row in the table (easy to do with emacs)? And, can I put
this code in models.py after the classes?

Rich


Re: Adding a lookup table

2017-06-29 Thread Rich Shepard

On Wed, 28 Jun 2017, Rich Shepard wrote:


Yes, that's the way to do it. I wrote my first idea before realizing that
two models/tables would be the way to go.


  After further consideration I realized that a single model/table is the
way to go. Because each city needs to be associated with a county a separate
model/table of county names adds nothing useful.

  Now I need to learn how django allows me to populate that table. The SQL
'INSERT INTO' statement can be appended to the CREATE TABLE command and both
read into the database using psql.

Thanks,

Rich




Re: Adding a lookup table

2017-06-28 Thread Rich Shepard

On Wed, 28 Jun 2017, Rich Shepard wrote:


appropriate county list. Example, Drewsey in Grant Co.


  Oops! Drewsey is in Harney Co.

Mea culpa!

Rich


Re: Adding a lookup table

2017-06-28 Thread Rich Shepard

On Wed, 28 Jun 2017, John Thomas wrote:


Could you create a City model and a County model and relate them one
County to many Cities? I'm not sure how to populate those tables.


John,

  Yes, that's the way to do it. I wrote my first idea before realizing that
two models/tables would be the way to go.


As an aside, where do you get your City to County data. I've been meaning
to look for that data.


  My initial focus is on Oregon; Washington's next. Using duckduckgo.com I
entered the search term, "oregon cities by county," and found two useful
sites: 'Oregon Blue Book: Incorporated Cities: Arranged by County' and
'Oregon City to County Reference - A Cross-Reference List for ...'. I'm sure
other states will have similar sites.

  Of course, not all cities are incorporated so when I find one not in the
list I assembled I do a bit more research, then add the name to the
appropriate county list. Example, Drewsey in Grant Co.


Do all cities cleanly break into one county?


  As far as I know, yes. At least in OR, WA, ID, NV, UT, WY, and MT. Some
cities are counties, I believe, and in New York City each borough is a
separate county.

Thanks,

Rich


Adding a lookup table

2017-06-28 Thread Rich Shepard

  I want to add a lookup table to my application. The table will have two
columns: city_name and county. This will allow me to return all rows for
companies in a specific county (or all companies sorted by county). I know
how to do this with SQL and want to learn how to implement this capability
in django (1.11.2 currently installed). Pointers to the appropriate docs
much appreciated.

Rich


Re: 'migrate' does not find existing postgres database

2017-06-26 Thread Rich Shepard

On Mon, 26 Jun 2017, Vijay Khemlani wrote:


Maybe I'm misunderstanding, but you don't access PostgreSQL databases
as normal files with a path.

If you were using SQlite that might work, but not on typical SQL
databases (MySQL, Postgres, etc)


Vijay,

  That would do it. I took the default settings.py and changed the db name
without noticing that it does not need the default path in the file.

Thanks,

Rich


'migrate' does not find existing postgres database

2017-06-26 Thread Rich Shepard

  This is my first django project and is intended for my own use, but I'll
put it on git-hub when it's working.

  The database backend is postgresql-9.6.3 and exists in /var/www/htdocs/.
When I run 'python3 manage.py migrate' django looks for the database in
~/development/crm_project/crm/ and does not find it there. In settings.py I
have defined the engine:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.path.join(BASE_DIR, 'crm'),
'USER': 'rshepard',
'PASSWORD': '',
'HOST': '',
'PORT': '5432',
}
}

  Again, this is for my use and the database with its existing tables lives
in the same cluster with all my other databases. And, each table will be a
separate app; the models have been translated from sql to django.

  I'd appreciate suggestions on how to proceed.

Rich


Re: First models.py needs tuning

2017-04-21 Thread Rich Shepard

On Fri, 21 Apr 2017, Michal Petrucha wrote:


If you want to be able to gracefully handle violations of those
constraints, and produce more meaningful error messages (for example, when
validating a form that processes one of these models), you'd also
implement those checks in Python, either in your models' clean methods, or
if it's a constraint only involving a single field, you can also just add
a custom validator to that field.


Michal,

  Yes, I can see validating data entered by users in the view or a class
method. I'm used to letting postgres do as much work as possible because
it's quicker and cleaner. So I adapt my thinking and learn to do it Django's
way.

  There are two fields in one class where data needs to be restricted to
certain values. I'll learn to write custom validators for those two fields.


I'll let Django do this. However, should I still specify
unique_together() for the columns that would have comprised the PK?


Indeed – if you want to be certain that those natural keys are really
keys, you should list them in unique_together. That will enforce
uniqueness both with UNIQUE constraints in the table definition, as
well as higher-level validation in Python.


  As I thought. I did not think of adding the UNIQUE constraint to the
appropriate fields, but will.

Many thanks,

Rich


Re: First models.py needs tuning

2017-04-21 Thread Rich Shepard

On Fri, 21 Apr 2017, Michal Petrucha wrote:


For the foreseeable future, though, I'd strongly recommend that you save
yourself a lot of trouble, and just add a surrogate primary key field to
all your tables and models.


Michal,

  I'll let Django do this. However, should I still specify unique_together()
for the columns that would have comprised the PK?

Regards,

Rich


Re: First models.py needs tuning

2017-04-21 Thread Rich Shepard

On Fri, 21 Apr 2017, Michal Petrucha wrote:


I have bad news for you – Django does not at this point in time have
support for multi-column primary keys. A large part of the ORM is built
around the assumption that each model instance is identified by a single
field acting as its primary key.


Michal,

  Ah, okay. I did not get far enough into the docs to read this.


For the foreseeable future, though, I'd strongly recommend that you save
yourself a lot of trouble, and just add a surrogate primary key field to
all your tables and models.


  I can live with this. Many, if not most, of the databases I've developed
will have a table which stores a unique value based on more than one other
table row. But, using a surrogate key works as long as I can retrieve the
appropriate records. Guess I'll get to that point in the not too distant
future.

  What about my other question? When I want to limit acceptable strings in a
data entry field to a provided list, as in postgres's check constraint? Is
Mike's suggestion of clean() the way to handle these?

Thanks very much,

Rich


Re: First models.py needs tuning

2017-04-20 Thread Rich Shepard

On Fri, 21 Apr 2017, Mike Dewhirst wrote:

In the more usual scenario you specify your models using Python and let the 
Django ORM framework do the SQL. If that is your case ...


Mike,

  I wrote the schema for postgres but had not created the database. So I
renamed the file models.py and converted the tables to classes.


1. No need for a PK. Django automatically inserts a PK. You can refer to
this in your code as model_id or model.id where "model" is the lower-case
class name of the model. This is best-practice.


  I understand that Django creates the PK when a class has only a single
variable. I have a table that contains one FK and two other variables form a
combined primary key. Perhaps this is a case for the many-to-one model type
in Django?


3. In the case of 1 above I would expect three models being Company,
Person and Project each of which would have a PK managed by Django. If so,
the model you are designing (possibly Project) presumably has a field
called 'proj_nbr' and foreign keys to Company and Person. Those FKs are
represented in your model as company = models.ForeignKey('Company') and
person = models.ForeignKey('Person')


4. Within each model is a class Meta: to carry various options for the model 
as a whole. The option you are looking for is: unique_together = (('company', 
'person', 'proj_nbr'),)


  Here's one class which requires three columns to make each row unique:

class Projects (models.Model):
company=models.ForeignKeyField('Companies', on_delete=models.CASCADE)
person=models.ForeignKeyField('Contacts', on_delete=models.CASCADE)
proj_nbr=models.CharField(max_length=8, Field_null=True)
proj_name=models.TextField(Field_null=True)
description=models.TextField()
PRIMARY KEY unique_together=('company', 'person', 'proj_nbr')

  If I delete 'PRIMARY KEY' and leave the rest of the line, does this
provide the relational integrity?


  This I'll need to ponder more to figure out where to put the clean method
so it validates entries before they're saved.


I put the clean() method after the save() method which follows the __str__() 
method which follows the Meta class. It doesn't really matter so long as you 
are consistent.


  Okay. I'll try writing these methods after I get the multi-variable PKs
correct.

Another place I sometimes use is the save() method. Django also provides 
pre_save and post_save hooks so you never need to use database triggers.


  This goes beyond what I've learned. I'll get there step-by-step.

  Yes, you are helping me smooth off the rough spots.

Thanks,

Rich


Re: First models.py needs tuning

2017-04-20 Thread Rich Shepard

On Wed, 19 Apr 2017, Mike Dewhirst wrote:


You probably need a single FK plus a meta option of unique_together
https://docs.djangoproject.com/en/1.8/ref/models/options/#unique-together


Mike,

  Okay. What would be the correct syntax for
PRIMARY KEY unique_together=('company', 'person', 'proj_nbr')


Use the model's clean() method ...
https://docs.djangoproject.com/en/1.8/ref/models/instances/#django.db.models.Model.clean


  This I'll need to ponder more to figure out where to put the clean method
so it validates entries before they're saved.

Thanks,

Rich



Re: First models.py needs tuning

2017-04-18 Thread Rich Shepard

On Wed, 19 Apr 2017, Mike Dewhirst wrote:


You probably need a single FK plus a meta option of unique_together
https://docs.djangoproject.com/en/1.8/ref/models/options/#unique-together



Use the model's clean() method ...
https://docs.djangoproject.com/en/1.8/ref/models/instances/#django.db.models.Model.clean


Mike,

  I'll read how to use these.

Thanks,

Rich



First models.py needs tuning

2017-04-18 Thread Rich Shepard

  Converting from the postgres schema to a Django models.py for my first
Django project. Most of the syntax (64 lines in the file) should be correct,
but there are two conditions that I have not found how to handle.

  First, a couple of classes have primary keys with three fields. I know
there's a models.PrimaryKey but haven't found an example of how to apply
that to a field that foreign key fields.

  Second, I have a couple of fields with postgres check constraints; that
is, valid data is restricted to a list of strings. I've not found a Django
model field validator teaching me how to write this.

  If you would be willing to look at the module, show me how to write the
two conditions above, and check syntax on the all 5 classes in it I will
send you the file off the mail list.

Rich


Project layout

2017-04-14 Thread Rich Shepard

   As a Django newcomer I'm still confused about project layout naming
conventions. Following the author's layout in '2 Scoops' chapter 3 for a
project I'm building for my own use to manage prospects and clients, I ran
cookiecutter pointing to pydanny's cookiecutter-django. I have several
subdirectory layers with two of them having the same name, and I need
clarification for these.

   My directory tree looks like this (plain ASCII text in my MUA, alpine):

clientmgmtsystem_project/
+-- clientmgmtsystem
 +-- clientmgmtsystem
 |   +-- contrib
 |   |   +-- sites
 |   |   +-- migrations
 |   +-- static
 |   |   +-- css
 |   |   +-- fonts
 |   |   +-- images
 |   |   +-- js
 |   |   +-- sass
 |   +-- templates
 |   |   +-- account
 |   |   |-- bootstrap
 |   |   |   +-- layout
 |   |   +-- pages
 |   |   +-- users
 |   +-- users
 |   +-- migrations
 |   +-- tests
 +-- config
 +   +-- settings
 +-- docs
 +-- requirements
 +-- utility

   Directly under the top-level directory are the clientmgmtsystem/
subdirectory which contains another subdirectory with the same name. I
assume the topmost one is the Django project name, but what is the second
one? If I want to invoke the application using 'edb' as the application
name, which directory needs to be renamed?

Looking forward to learning,

Rich


Project layout

2017-04-14 Thread Rich Shepard

  As a Django newcomer I'm still confused about project layout naming
conventions. Following the author's layout in '2 Scoops' chapter 3 for a
project I'm building for my own use to manage prospects and clients, I ran
cookiecutter pointing to pydanny's cookiecutter-django. I have several
subdirectory layers with two of them having the same name, and I need
clarification for these.

  My directory tree looks like this (plain ASCII text in my MUA, alpine):

clientmgmtsystem_project/
└── clientmgmtsystem
├── clientmgmtsystem
│   ├── contrib
│   │   └── sites
│   │   └── migrations
│   ├── static
│   │   ├── css
│   │   ├── fonts
│   │   ├── images
│   │   ├── js
│   │   └── sass
│   ├── templates
│   │   ├── account
│   │   ├── bootstrap4
│   │   │   └── layout
│   │   ├── pages
│   │   └── users
│   └── users
│   ├── migrations
│   └── tests
├── config
│   └── settings
├── docs
├── requirements
└── utility

  Directly under the top-level directory are the clientmgmtsystem/
subdirectory which contains another subdirectory with the same name. I
assume the topmost one is the Django project name, but what is the second
one? If I want to invoke the application using 'edb' as the application
name, which directory needs to be renamed?

Looking forward to learning,

Rich


Re: How to structure this django application

2017-04-08 Thread Rich Shepard

On Sat, 8 Apr 2017, Sithembewena Lloyd Dube wrote:


Do take the time to peruse the book. It would be time well spent. Also, do
keep in mind that the recommendations therein do not apply to a Django
blog or CRM sustem etc, per se. They would apply just as well if you were
building a RESTful mobile app backend.


Sithembewena,

  I recognized this the first time I considered using django.


The problem you describe of managing users etc is just a requirements
specification. The advice in the book is general enough across
implementations of solutions in broad problem domains. It's not a recipe
book, but more a collection of chefs' knives.


  My original question was not about structuring django code but the logical
design of the project itself. I believe that question was answered by a
message on another thread: there is at least one plug-in package that allows
individual users to work in their own database area and keeps users from
areas assigned to others. This is independent of the django project/app code
arrangement.

Thanks again,

Rich


Re: How to structure this django application

2017-04-07 Thread Rich Shepard

On Sat, 8 Apr 2017, Sithembewena Lloyd Dube wrote:


My best recommendation for structuring Django projects (and for
optimization and a myriad other goodies) would be the book Two Scoops of
Django by Daniel and Audrey Roy Greenfeld. I could say a lot but the bottom
line is, check the book out. It's at https://www.twoscoopspress.com/


Sithembewena,

  I have that book (the 1.8 version); pulled it off the shelf earlier today
to read again.


There are various factors to consider and this book (to me, at least) best
encapsulates all those. I believe that it also applies for newer versions
of Django than v1.8.


  What I need to build is different from a blog, newspaper, e-commerce, and
similar sites ... I think. In those, every visitor/user sees the same views
and has the same options.

  My proposed application needs to be slightly different for each category
of user and keep each in his/her own private section. How to do this may be
in 2 scoops, or may not. If I don't see how to do this I'll be back with
more questions.

Thanks,

Rich


How to structure this django application

2017-04-07 Thread Rich Shepard

  Caveat: I'm not a professional coder or web developer, but have written
many applications over the years. Because I'm also new to django I need
insights into how to structure an application application supporting
multiple users, each in its own private section.

  This application will allow my clients to upload data to the web site,
each in his own space. Data will be stored in a postgres-9.6+ backend.
Generated reports will be available for download.

  I understand that a django application has many 'apps' in it and is not a
single-file framework. If there is an example of how to set up and structure
such an application please point me to it so I can learn from success.

  Pointers, references to docs or web sites will be appreciated and used.

TIA,

Rich


Re: Convert PostgreSQL tables to django

2016-10-29 Thread Rich Shepard

On Sat, 29 Oct 2016, m1chael wrote:


https://docs.djangoproject.com/en/1.10/howto/legacy-databases/


  I missed seeing that. Thanks very much.

Rich


Convert PostgreSQL tables to django

2016-10-29 Thread Rich Shepard

  Is there a tool to convert postgres DDL to django model syntax? It would
sure save a lot of time and effort if there is a converter.

Rich


Unexpected poor template performance

2016-09-12 Thread Rich Rauenzahn

I'm working on a project that needs to occasionally render very large 
tables -- I'm picking hundreds of thousands of cells as a test point for 
trying out back end implementation scalability.

I'm parallelizing some of the rendering through ajax calls that returns 
large subsets of the rendered cells ("content") within 
a JSON structure.  I'm using a short template to render each cell:


  {{ datapoint.score }}



template = get_template('cell.djhtml')

for datapoint in self._iterate_datapoints():
datapoint_cell[datapoint.foo_id][datapoint.bar_id] = 
template.render(dict(datapoint=datapoint))


If I change the template.render() call to just a "%s" % datapoint.score, the code is an order of magnitude 
faster.

My assumption (and my reading of the django code I think confirmed) that 
the template is compiled only once, so I'm ok there.

Is this difference surprising or unexpected?  Would a single (consolidated) 
render() be expected to be much faster? (I'm trying to think of a way to 
refactor it to a single render, but I'm not looking forward to rendering 
json in a django template)

I'm also considering I may just need to return structured json and create 
the elements manually on the client side -- although if I have to do it 
that manually, I might as well use interpolation on the backend python 
without using a template...

Oh, and I just tried jinja2 -- it was much closer to interpolation speed.   
Perhaps that is my best answer.

Any thoughts or pointers on my predicament?

Thanks!
Rich

-- 
You received this message because you are subscribed 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/cb85b941-964c-46c8-8e84-148fdb6049ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: less-css

2016-09-02 Thread Rich Shepard

On Fri, 2 Sep 2016, Aron Griffis wrote:


There isn't a conflict between them, because the LESS compiler installs as
"lessc" and also because you'll want to install it locally using npm rather
than system-wide.

These links might be helpful to you:

https://github.com/caktus/django-timepiece#installation
https://docs.npmjs.com/getting-started/installing-npm-packages-locally
http://lesscss.org


  Thanks, Aron. I assumed there'd be no conflict but appreciate the
confirmation. I saw less in the django-timepiece requirements file which
raised my question.

  Will look at the last two URLs first; need to install requirements before
trying django-timepiece.

Regards,

Rich


less-css

2016-09-02 Thread Rich Shepard

  The django-timepiece project requires a tool called 'less,' a css
preprocessor. However, on linux systems (if not also other unices)
/usr/bin/less is a pager with greater capabilities than more.

  Is there a conflict between these two? Where would the css-less be
installed?

TIA,

Rich


Re: Project time and expense tracking [RESOLVED]

2016-09-02 Thread Rich Shepard

On Fri, 2 Sep 2016, Rich Shepard wrote:


I'll definitely look at the project management packages.


  It appears that django-timepiece will fulfill my needs.

Thanks again,

Rich


Re: Project time and expense tracking

2016-09-02 Thread Rich Shepard

On Fri, 2 Sep 2016, Tim Graham wrote:


I see some results by searching "django time tracking app" in a search
engine. In particular, Django Packages has a nice comparison of some
options: https://djangopackages.org/grids/g/project-management/


Tim,

  That's a much better search string than those I used. I'll definitely look
at the project management packages.

Much appreciated,

Rich



Project time and expense tracking

2016-09-01 Thread Rich Shepard

  Before I re-invent the wheel, does anyone know of an existing django
project time and expense application using sqlite3?

  Now and then a client needs to be invoiced by time and expense rather than
a flat rate. My financial software is supposed to do this, but I've never
been able to convert the time card records into a line-item invoice, and I
find nothing suitable in my Web searches (because they either do not run on
linux or require MySQL as the backend database.

  It should not be too difficult to put together this application if one's
not already available.

TIA,

Rich



Re: Django documentation release 1.10.1a1

2016-08-30 Thread Rich Shepard

On Tue, 30 Aug 2016, Tim Graham wrote:


I don't think there have been any recent changes to the styling, but if
you'd like to contribute, the place to look is probably
https://github.com/django/django/tree/master/docs/_theme.


Tim,

  I don't know what to do once I'm on that page but when time permits I'll
look around and see if I can find the source. Wonder if it's written in
LaTeX; if so, the typefaces can easily be change.

Thanks,

Rich


Django documentation release 1.10.1a1

2016-08-30 Thread Rich Shepard

  I don't know how this PDF displays in other viewers, but in xpdf, mupdf,
and acroread important strings in the text are very difficult to read
because they have very low contrast with the white background.

  For example, comments are in a light grey and important strings are in a
very pale yellow. Page 14 has many examples of this.

  Perhaps for very young eyeballs it's not an issue, but for those of us
with many miles on our eyes it's extremely hard to read this light text on
the white background.

  It would be very helpful if this situation was quickly remedied and a
revised version released.

Thanks in advance,

Rich


Re: Clarifying Project vs Apps

2016-08-24 Thread Rich Shepard

On Wed, 24 Aug 2016, Andromeda Yelton wrote:


My feeling/practice on apps is: each app is a one-word informative noun.
It contains the models that are logically grouped under that noun (and the
views, urls, etc required to interact with those models on the front end).


Andromeda,

  So are table names.


If there isn't a single word that logically represents all my models, then
they need to be separated into multiple apps. (And if models.py has gotten
long enough that it's unwieldy, it probably wants to be split.)

So, e.g., "companies" or "invoices" or "customers" or "reports" are all
perfectly decent app concepts.


  Got it, thanks.


Also, _Two Scoops of Django_ is a helpful book for developing Django best
practice intuitions.


  I have the one from django-1.5; the latest is for -1.8. Since the current
version is 1.10 I see no reason to get a newer, but still two versions
behind, copy.

Thanks very much,

Rich


Re: Clarifying Project vs Apps

2016-08-24 Thread Rich Shepard

On Wed, 24 Aug 2016, Andreas Kuhne wrote:


If you know how your project will be used, you can usually group the models
and views in logical apps. For example a customer app that has the customer
(user) model, address model. Then another app for orders and invoices and
so on.


Andréas,

  Here you've given me an alternative approach for my application slightly
different from Lee's way of presenting it. Much to think about before I
proceed.

Much appreciated,

Rich



Re: Clarifying Project vs Apps

2016-08-24 Thread Rich Shepard

On Wed, 24 Aug 2016, Lee Hinde wrote:


So, no one is going to grade it. You're making this for yourself, so I
wouldn't over think it. I'm working on a project now that only has two
apps, one with all the core models and one for utility models (like choice
lists).(I'm using several packages, so the database has more to it than
that.)



It sounds like something like that would work for you and still be 'right'.
Especially as a first time out of the gate project, keep it simple. IMHO.


Lee,

  Now this is a valuable lesson: core models and utility models. Many of my
classes have choice lists (select from a list of industries, or campaign
types) so I'll put those in the models.py of a separate app.


While it will certainly evolve as you use it, you're not gong to suddenly
wake up and need 18 more apps to meet your needs. And if that does happen,
you can rearrange.


  No, not on this project. But the next one will require more apps because
it has more functional groupings.

Many thanks again,

Rich


Re: Clarifying Project vs Apps

2016-08-24 Thread Rich Shepard

On Wed, 24 Aug 2016, Lee Hinde wrote:


My tuppence.


Lee,

  Before or after Brexit? The value might change. :-)


No, an app is a logical grouping of objects/tables. You might, for
instance,have an Invoice app that would include an Invoice table (model)
and a LineItems table. Products and related tables would be in a different
app.


  OK, that makes sense.

  In my current project, then, all modules for company, contact, activity,
case, etc. will be in a single app. And, perhaps, another app would be for
reporting?

  Translating from product-oriented applications to service-oriented ones is
not always easy.

Thanks very much,

Rich


Clarifying Project vs Apps

2016-08-24 Thread Rich Shepard

  While I think that I understand the differences between a project and its
apps there remains one point of uncertainty. I've not found the answer,
although it might be in the 1.10 docs or on the Web and I've missed it.

  If the project represents the entire database, do the apps represent
individual tables? That is, should my project have a separate app for each
table with its models, templates, and views with templates of joined tables
in the main project subdirectory? Or are all tables in a single app?

TIA,

Rich



Re: Using version control with django

2016-08-23 Thread Rich Shepard

On Tue, 23 Aug 2016, Gergely Polonkai wrote:


On the other hand, you definitely should choose a distributed version
control if you are working alone. For example, Git, Mercurial and Fossil
repositories are self contained, which means the whole development history
is located right where you work.


Gergely,

  SVN is also self-contained, unless a separate repository is created for
each project. Regardless, after looking at some docs I decided to move from
svn to git. Since I'm not a professional developer I don't know it will make
any difference to me, but ...

  I also keep versions of important documents, such as books or articles
submitted for publication and drafts of my expert opinons when I'm retained
for litigation support. While svn had no problem keeping each branch of its
repository tree separate, perhaps the maintenance of separate repositories
(one for each project) will not be onerous.

Suggestion taken,

Rich


Re: Using version control with django

2016-08-23 Thread Rich Shepard

On Tue, 23 Aug 2016, François Schiettecatte wrote:


I would add a +1 for git, I started off with svn and switched to git,
branching and merging is much easier which really helps when you want to
test ideas.


François,

  Thanks for your insight,

Rich


Re: Using version control with django

2016-08-23 Thread Rich Shepard

On Tue, 23 Aug 2016, Gergely Polonkai wrote:


You should put all the stuff under trunk/, so it becomes trunk/manage.py,
trunk/crm/, etc. If you are developing for multiple customers, the
branches and tags directory may come in handy later. Also, it's nothing
but naming convention: you can call these directories dog/, Pete/, and
ananas/. But that’s more for a Subversion user list, not Django.


Gergely,

  That's what I suspected to be the case.


On the other hand, you definitely should choose a distributed version
control if you are working alone.


  Well, subversion's served me well since I replaced CVS with it. Backups
are daily (using dirvish) and since the repository's been in the same place
for almost a couple of decades it's not likely to be moved. :-)

Thanks for confirmation,

Rich


Using version control with django

2016-08-23 Thread Rich Shepard

  I want to track django projects with subversion. (Single developer, local,
so svn is better suited than the distributed git and mercurial.) I'd like
advice on how to lay this out vis-a-vis the django layout.

  Project overall root is ~/development/crm-project. This directory
contains:

Makefile  README  crm-project/  docs/  manage.py*  requirements.txt

  The top-level project directory is the same-named crm-project, and this
contains:

__init__.py   __pycache__/  settings.py   urls.py
__init__.pyc  crm/  settings.pyc  wsgi.py

  The app directory is crm/.

  So, where should I place trunk/, tags/, and branches/ be created? If
they're in the overall project root (~/development/crm-project/) should I
then move that directory's contents into the newly made trunk/ subdirectory?

  I find nothing in my web searches for using svn with django. Perhaps my
web foo is insufficient.

Rich


Re: Starting new project -- version 1.10

2016-08-23 Thread Rich Shepard

On Tue, 23 Aug 2016, Michal Petrucha wrote:


This is mostly an issue with how we name things. You have a project, which
is a CRM application. That's the entire thing, which consists of a bunch
of different Python packages. So, each of the subdirectories in the
top-level “clientmanagement” directory is one Python package. For better
or for worse, Python packages containing Django models, views, URL
patterns, and whatnot, are referred to as “Django apps”.


Michal,

  Yesterday evening I started reading a book I bought several years ago
(when django was at version 1.5) for a project that got sidelined. With your
explanation and the book I'm starting to understand the django terminology
and project organization.


Usually, it's a good practice to split your project into smaller
self-contained packages. Those all live together inside the project
directory, and each of them can have its own URL patterns, models, views,
static files, templates, and pretty much anything else. They can even
depend on each other, although it's often a good idea to keep the coupling
between as low as possible.


  Let me test my understanding by explaining my crm project. Getting it
right from the beginning will help me a lot.

  First, this is a single-user project for my business; I'm not a
professional application developer but have built scientific and business
tools for my use for several decades. Since this, and the other django
application that has been put off for a while, are the only two that I plan
to develop I am not convinced that I need virtualenv and its wrapper. Each
will use python3 and I'll keep django upgraded to the latest version.

  Second, now that I better understand the project/app design and disk
layout I'll rename some directories so the distinctions are clearer. Which
leads to my question about apps in a project.

  Yesterday, in models.py, I set up the schema based on what I want. The crm
has several components: companies, contacts, activities, opportunities, etc.
Each of these is a single class within models.py. My question is whether
each should be a separate app since there will be methods for adding,
modifying, and deleting rows in the database tables as well as report
generation and views that incorporate data from multiple tables. If so, is
each named as a distinct python module and imported into the main models.py?

  Or, should they all remain in models.py with separate modules for adding,
editing, deleting, and reporting that are imported to models.py?

  My python2/wxPython applications have an organization that makes sense to
me and works. Since building a browser-based django application is a new
experience I want to learn how best to organize everything.

Thanks for the insights,

Rich



Re: Starting new project -- version 1.10

2016-08-23 Thread Rich Shepard

On Tue, 23 Aug 2016, Carsten Fuchs wrote:

I cannot remember where is was stated, but iirc another reason for the 
“project-under-the-project” subdirectory was that it is considered not as 
app, but rather as “site”.


Carsten,

  Thanks for the clarification. That helps.

Rich


Re: DateField default value

2016-08-22 Thread Rich Shepard

On Mon, 22 Aug 2016, Tim Graham wrote:


What do you mean by "not accepted"? Is there some error message? What you
wrote should work as far as I know.


Tim,

  Yes, there was an error message that was not saved.


from datetime import date


  That's probably the cause: my missing that import in the tutorial.

Thanks!

Rich


DateField default value

2016-08-22 Thread Rich Shepard

  Reading the doc for DateField() I tried to set the default as today's
date, but 'default=date.today' is not accepted.

  If there is a way to set today's data as the default for a DateField()
please point me to the doc for it.

Thanks,

Rich


Re: Starting new project -- version 1.10

2016-08-22 Thread Rich Shepard

On Mon, 22 Aug 2016, Michal Petrucha wrote:


Just to add to what Tim wrote, there's no reason why you couldn't use the
crm package created by startproject as an “app”, too – all you have to do
is create a models.py file in there (next to the existing urls.py, if you
need any models), views.py (if you need views), and add 'crm' to
``INSTALLED_APPS``. That's pretty much the same thing as what startapp
would have done, anyway.


Michal,

  Thanks for the insight.

  Seems to me that models and views are essential to a django application.
Regardless, I saw why startapp failed: I overlooked the requirement to
create a postgres database from the commandline prior to asking django to
use it.

  INSTALLED_APPS now has 'crm' at the end of the django.contrib.* list.

  One clarification on projects vs applications will help my learning.
Rather than using the same name for both (based on prior advice), the
project name is clientmanagment and that directory contains
clientmanagement/  crm/  manage.py*

  The clientmanagement/ subdirectory contains
__init__.py   __pycache__/  settings.pyc  wsgi.py
__init__.pyc  settings.py   urls.py

and I wonder why the project-related files in this subdirectory are not
under the parent project directory. In other words, why is there a project
subdirectory under the project directory?

Thanks,

Rich



Re: Starting new project -- version 1.10

2016-08-19 Thread Rich Shepard

On Fri, 19 Aug 2016, Tim Graham wrote:


Don't use the same name for your app and project. When you "startproject
crm", the project settings.py, urls.py, and wsgi.py are placed in a module
named "crm" so you can't use the same name for an app.


Tim,

  I read that but overlooked the implications.

Thanks very much,

Rich


Starting new project -- version 1.10

2016-08-19 Thread Rich Shepard

  I'm working my way through the tutorial and creating the application I
want rather than the articles example. I've become stuck between two
sections of the tutorial.

  Creating the project (section 2.3.1 worked fine from the TLD,
~/development/:

django-admin startproject crm

created ~/development/crm/ containing the files it should (page 14).

  Moving to section 2.3.2 I start the runserver and, sure enough, I can see
the web page it created.

  The problem occurs in section 2.3.3 when I try to create the crm
application. I cannot do this while the development server is running; there
is no system or python prompt. When I kill the running development server
(^C), and issue the command
python3 manage.py startapp crm

I'm told that application already exists:
~/development/crm]$ python3 manage.py startapp crm
CommandError: 'crm' conflicts with the name of an existing Python 
module and
cannot be used as an app name. Please try another name.
but I have no idea where django thinks it exists.

  Not all the files are found:
~/development/crm/crm]$ ls
__init__.py  __pycache__/  settings.py  urls.py  wsgi.py

These were created by the startproject command.

  Now knowing how I dug this hole I'm in I'd appreciate your teaching me how
to get out of the hole and move on.

Rich


Re: Advice on python version for new project

2016-08-16 Thread Rich Shepard

On Tue, 16 Aug 2016, Avraham Serour wrote:


https://virtualenv.pypa.io/en/stable/


  Thanks, Avraham. Looks interesting.

Rich


Re: Advice on python version for new project

2016-08-15 Thread Rich Shepard

On Tue, 16 Aug 2016, Avraham Serour wrote:


you should also create a virtualenv for the project


Avraham,

  OK. Please point me to some docs for this.

Regards,

Rich


Re: Advice on python version for new project

2016-08-15 Thread Rich Shepard

On Mon, 15 Aug 2016, Rich Shepard wrote:


I'll have to learn how to get it to install in -3.5.2, too.


  Found the answer: pip3.

Rich


Re: Advice on python version for new project

2016-08-15 Thread Rich Shepard

On Mon, 15 Aug 2016, Ari Davidow wrote:


If you're doing a CRM app, many advantages to using Python 3 and not having
to deal with 2's Unicode issues.


Ari,

  This is for my use only. I've outgrown the tools I've been using for my
consulting business and need to consolidate them in a single application.
Will use python3, however.

Thanks,

Rich


Re: Advice on python version for new project

2016-08-15 Thread Rich Shepard

On Mon, 15 Aug 2016, Nick Santos wrote:


I'd recommend Python 3 at this point unless you encounter a good, specific
reason to use Python 2.


Nick,

  I'll take your advice. I have both -2.7.5 and -3.5.2 installed. Using pip
to install django puts it in only the 2.7.5/site/packages/ subdirectory.
I'll have to learn how to get it to install in -3.5.2, too.

Thanks,

Rich


Advice on python version for new project

2016-08-15 Thread Rich Shepard

  The django web site suggests that new projects use python3 unless required
dependencies are not yet available for that version. I've no idea what
python dependencies I'll need for this job.

  What I want to do is convert an abandoned php application (last upgraded a
decade ago) to django. The application is XRMS, an open source CRM (client
relationship manangement tool in my case) that is perhaps the only one that
supposedly supported postgresql via adodb. What I learned over the weekend
is that I cannot even install it and cannot find the reason why it's not
connecting to the db back end.

  A posting on a forum thread from 2007 reported that postgres was not
supported unless all extensions (none of which I need) are installed, and
all those extensions are hard coded for mysql. I have source code, schema,
and a very full set of docs; suprizingly complete.

  I suppose there's no reason to not use python-2.7.5 installed here for
this project, unless you advise me otherwise. I also need some advice and
guidance on how to proceed on creating a django application from the php
source files.

TIA,

Rich



Re: Fixtures won't load twice in same testcase

2016-05-12 Thread Rich Rauenzahn


On Friday, May 6, 2016 at 4:11:42 AM UTC-7, Alasdair Nicol wrote:
>
>
>>
>> But In this particular run I'm currently tracing, rich is already in the 
>> db (as the only entry) as pk=5 (via fixture loading process).   For one, 
>> this tells me the sequence generators aren't always resetting between 
>> fixture loads/tests.
>>
>>  
> Sequences *are not* reset between test cases by default [2]. Perhaps you 
> need to change your code so that it doesn't assume that the user has pk=1, 
> or set reset_sequences = True.
>

My code didn't make that assumption -- it appeared that the fixture loading 
code did.
 

>
> It's difficult to offer any more advice, because you haven't posted any 
> code that can reproduce the problem. It doesn't need to be the actual code, 
> in fact the simpler the example is the better.
>

I spent some cycles trying to reproduce on a fresh Django install, but 
couldn't based on my assumptions.  As I replied later, the problem was a 
setUpClass() creating objects via a factory that persisted between 
TestCase's that did fixture loading, and they conflicted.

Rich 

-- 
You received this message because you are subscribed 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/3f1c6bfe-45be-48d8-bb94-a9a43acb8eb6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Fixtures won't load twice in same testcase

2016-05-12 Thread Rich Rauenzahn


On Thursday, May 5, 2016 at 4:22:11 PM UTC-7, Mike Dewhirst wrote:
>
> Are you using setUp() and tearDown() as class methods in your test class? 
>
>
No, the code was using setUpClass(), which is a classmethod. 

-- 
You received this message because you are subscribed 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/01e41a08-d956-4946-a6cf-e82644201cf6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Fixtures won't load twice in same testcase

2016-05-05 Thread Rich Rauenzahn

I've been tracing into django core code, and it looks to me that I have a 
case where the fixture has a auth.User(username=rich) with a pk=1 in the 
fixture.  But sometimes as the User fixture with pk=1 is being added 
(updated?) through Model._save_table(), the same User with pk=5 is already 
in the db (did not exist prior to fixture loading).  This causes the django 
core code (Model._save_table()) to also try to insert another user with the 
same username, causing an integrity error.

I added my own _fixture_setup() that asserted my db was clean prior to 
fixture loading.  It failed!  This lead me to find objects being created in 
a TestCase.setUpClass rather than TestCase.setUp(), and so were leaking 
across tests, fouling up fixture loading.

What's odd is that django-nose's FastFixtureTestCase hid this problem. 
  I think it affected the ordering and ran all the fixture based test 
cases first before the db was polluted.   (But isn't the DB dropped and 
refreshed after every TestCase?)


-- 
You received this message because you are subscribed 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/c9d604a9-af10-4e22-91de-f81f3986d28d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Fixtures won't load twice in same testcase

2016-05-04 Thread Rich Rauenzahn

I'm having a strange problem.  My test environment has been working fine, 
but I am upgrading my environment's Django revision slowly, which means I 
also need to move away from django-nose's FastFixtureTestCase.

I'm now at Django 1.7.   I have a TestCase which is more or less...

class Foo(TestCase): # and I've tried TransactionTestCase

fixtures = ['accounts.json', 'config.json', 'runtimedata.json']

def test1(self):
pass # yes, literally.

def test2(self):
pass # literally, pass right now


If I split test1 and test2 into two classes, the TestCase works fine.

Otherwise, my runtimedata app fixture ends up with a duplicate row for the 
second test during the fixture setup phase.   When I turned on postgres 
(9.2) logging, I get:

LOG:  statement: UPDATE "runtimedata_branch" SET "name" = 'mock' WHERE 
"runtimedata_branch"."id" = 1
LOG:  statement: INSERT INTO "runtimedata_branch" ("id", "name") VALUES (1, 
'mock')
ERROR:  duplicate key value violates unique constraint 
"runtimedata_branch_name_49810fc21046d2e2_uniq"
DETAIL:  Key (name)=(mock) already exists.
STATEMENT:  INSERT INTO "runtimedata_branch" ("id", "name") VALUES (1, 
'mock')
LOG:  statement: ROLLBACK
LOG:  statement: DROP DATABASE "test_db"

If I grep for runtimedata_branch in the postgres logs, I get ...starting 
after the TRUNCATE caused by TransactionTestCase 

LOG:  statement: TRUNCATE [...], "runtimedata_branch", [...]; #
LOG:  statement: SELECT "runtimedata_branch"."id", 
"runtimedata_branch"."name" FROM "runtimedata_branch" WHERE 
"runtimedata_branch"."name" = 'mock' LIMIT 21
LOG:  statement: INSERT INTO "runtimedata_branch" ("name") VALUES ('mock') 
RETURNING "runtimedata_branch"."id"
LOG:  statement: UPDATE "runtimedata_branch" SET "name" = 'mock' WHERE 
"runtimedata_branch"."id" = 1
LOG:  statement: INSERT INTO "runtimedata_branch" ("id", "name") VALUES (1, 
'mock')
ERROR:  duplicate key value violates unique constraint 
"runtimedata_branch_name_49810fc21046d2e2_uniq"
STATEMENT:  INSERT INTO "runtimedata_branch" ("id", "name") VALUES (1, 
'mock')

You can see a different pattern for the first pass fixture loading for 
test1,

LOG:  statement: INSERT INTO "runtimedata_branch" ("name") VALUES ('mock') 
RETURNING "runtimedata_branch"."id"
LOG:  statement: UPDATE "runtimedata_branch" SET "name" = 'mock' WHERE 
"runtimedata_branch"."id" = 1

The main difference I can see is the first time, the tables are generated 
from scratch, the second the tables have been truncated.  Note, I get a 
very similar outcome with TestCase which does rollbacks instead of 
truncates.

Any ideas?  This is very odd.

Also, my fixtures are dumped with --natural.  I've just tried it without 
--natural and I get the same outcome.



-- 
You received this message because you are subscribed 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/89730e77-2099-4219-9e75-34ccc3b4f457%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Extending Form to include 'placeholder' text

2016-03-22 Thread Rich Rauenzahn
Hi,

I'd like to make a mixin to set the placeholder text in the widget attrs.

Reading this https://code.djangoproject.com/ticket/5793, it seems that 
extending Meta for custom fields is somewhat discouraged.

Would the following be the recommended way to do it?  Just adding a class 
variable to the Form class?

class PlaceHolderMixin(object): 



placeholders = {}   



def __init__(self, *args, **kwargs):   
 
super(PlaceHolderMixin, self).__init__(*args, **kwargs) 

for field_name, field in self.fields.items():   

if field_name not in self.placeholders: 

continue   
 
self.fields[field_name].widget.attrs['placeholder'] = 
self.placeholders[field_name]


class MyForm(PlaceHolderMixin, ModelForm):   


placeholders = {   
 
'name': 'blah blah',
'owner': 'blah blah',
}   



class Meta: 

model = MyModel
 

-- 
You received this message because you are subscribed 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/423a8164-47bb-498c-b651-48ea1a3f7464%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Announcing Django-Zappa - Serverless Django on AWS Lambda + API Gateway

2016-02-08 Thread Rich Jones
Hey guys!

I'm pleased to announce the release of Django-Zappa - a way to run 
serverless Django on AWS Lambda + API Gateway.

Now, with a single command, you can deploy your Django apps in an 
infinitely scalable, zero-configuration and incredibly cheap way!

Read the announcement post here: 
https://gun.io/blog/announcing-zappa-serverless-python-aws-lambda/
Watch a screencast here: 
https://www.youtube.com/watch?v=plUrbPN0xc8&feature=youtu.be
And see the code here: https://github.com/Miserlou/django-zappa

Comments, questions and pull requests are welcome!

Enjoy,
Rich Jones

-- 
You received this message because you are subscribed 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/dd2fe544-6300-49c2-9a9e-94b533796b53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Two-to-Many Mapping between Models in Django ORM

2015-07-30 Thread Rich Lewis
Hi Tom,

That was approximately what I was planning to do, I shall do some 
experimenting to see if I can do any more.  I was just wondering if there 
was a clever feature for this sort of thing, as ORMs seem pretty magic 
already!

Thanks,
Rich

On Thursday, 30 July 2015 17:15:40 UTC+1, Tom Evans wrote:
>
> On Thu, Jul 30, 2015 at 4:08 PM, Rich Lewis  > wrote: 
> > Dear All, 
> > 
> > I'm new to the Django ORM, and quite new to ORMs in general.  I have two 
> > models (lets call them A and B) between which I have an interesting 
> mapping. 
> > There are precisely 2 B instances associated with each A instance.  Each 
> A 
> > instance can have many B instances.  The order of Bs are important for 
> As. 
> > 
> > I want to do something like this: 
> > 
> > class A(models.Model): 
> >   b_1 = models.ForeignKey(B) 
> >   b_2 = models.ForeignKey(B) 
>
> This would fail here, when you have more than one foreign key to the 
> same model, you must supply a related_name argument on one of them, 
> which is used for the inverse relation on the related object. Which 
> leads us in to... 
>
> > 
> > class B(models.Model): 
> >   pass 
> > 
> > Such that i can do: 
> > 
> >>>> b1, b2, b3 = B(), B(), B() 
> >>>> a1, a2 = A(b_1=b1, b_2=b2), A(b_1=b2, b_2=b3) 
> >>>> b2.as 
> > [, ] #(order doesn't matter) 
>
> Typically, B instances would have an attribute named 'a_set' (the 
> lower case model name of the model it is related to, with "_set" 
> appended). When you have multiple relationships with the same model, 
> as I mentioned you must supply your own related_name arguments. In 
> which case, with the models you mentioned, you could then do something 
> like this: 
>
> >>> b2.a1_set.all() | b2.a2_set.all() 
> > [, ] 
>
> > 
> > I expect I could eventually do something a bit hacky that would work, 
> but 
> > what would be the best way to handle this? 
>
> I would say the above is the hacky way. You could have the same B 
> assigned to b_1 and b_2 and would have duplicates in the set, and no 
> way to specify DB constraints to limit it. 
>
> Given that you anticipate being able to retrieve all the A's for a 
> particular B, regardless of how they are related, I would model it as 
> a M2M with a through table holding any additional information about 
> the relationship, using the through table to add DB level constraints. 
>
> Cheers 
>
> Tom 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/daa601f5-12d5-44fe-8c58-f2f052629261%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Two-to-Many Mapping between Models in Django ORM

2015-07-30 Thread Rich Lewis
Oops sorry I meant every B instance can have multiple A instances.  Sorry!

On Thursday, 30 July 2015 16:21:37 UTC+1, monoBOT monoBOT wrote:
>
>
> 2015-07-30 16:08 GMT+01:00 Rich Lewis >:
>
>> There are precisely 2 B instances associated with each A instance.  Each 
>> A instance can have many B instances
>
>
> Isnt that a contradiction?
>
>
>
> -- 
> *monoBOT*
> Visite mi sitio(Visit my site): monobotsoft.es/blog/
>  

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


Two-to-Many Mapping between Models in Django ORM

2015-07-30 Thread Rich Lewis
Dear All,

I'm new to the Django ORM, and quite new to ORMs in general.  I have two 
models (lets call them A and B) between which I have an interesting 
mapping.  There are precisely 2 B instances associated with each A 
instance.  Each A instance can have many B instances.  The order of Bs are 
important for As.

I want to do something like this:

class A(models.Model):
  b_1 = models.ForeignKey(B)
  b_2 = models.ForeignKey(B)

class B(models.Model):
  pass

Such that i can do:

>>> b1, b2, b3 = B(), B(), B()
>>> a1, a2 = A(b_1=b1, b_2=b2), A(b_1=b2, b_2=b3)
>>> b2.as
[, ] #(order doesn't matter)

I expect I could eventually do something a bit hacky that would work, but 
what would be the best way to handle this?

Thanks in advance,

Richard

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3250c3c4-7598-4104-8a7b-1a0aa313a253%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Any interest in update_fields=dict(...)?

2014-06-10 Thread Rich Rauenzahn

I have a use case where I am retroactively adding save(update_fields=...) 
to an existing code base.  Sometimes the code is structured such that 
'self' of the model is modified in other helper methods of the model, but 
not saved immediately.  It seems like it would be useful to restructure the 
code such that these other methods modify a dict I pass around, and then 
when I am ready to save, I pass that dict to save() -- rather than guessing 
-- and hoping -- that I've listed (and kept up to date!) all of the 
relevant fields in the update_fields list.

It's kinda like:

class Foo(Model):
 
 def _go_do_the_complicated_stuff(self):
 self.a = ...
 self.b = ...
 ...

 def doit(self):
 self._go_do_the_complicated_stuff()
 self.done = True
 self.save(update_fields=[u???])

Where it could be:

class Foo(Model):
 
 def _go_do_the_complicated_stuff(self):
 return dict(a = ...,
 b = ...,
 ...)

 def doit(self):
 updates = self._go_do_the_complicated_stuff()
 updates['done'] = True
 self.save(update_fields=updates)

I like this because it is easy to inspect what is getting saved (and should 
be saved) at save time.

Implementation-wise, django would check update_fields for a dict (or just 
use another key) and do something like:

 for attr, value in d.iteritems(): 
setattr(self, attr, value)
 self.save(update_fields=d.keys())

Now, I know I can just make my own mixin (maybe add a save_dict()) to do 
this, but it seemed like something worth sharing.



Rich

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6f7f4bd1-1f63-4c16-92a8-600392792ff1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: FieldError, But Only In Production

2014-02-14 Thread Rich Jones
> are you using virtualenv?  it's possible that mod_wsgi was executing
> in a different environment than the test server.
>

>Or mod_wsgi is compiled for a different version of python and thus is
>finding completely different libraries.

Heh, it was neither of those things. No virtualenv on the machine, so
that's the same, and then mod_wsgi was version 2.6 and so is Python.

No matter now, but the mystery remains.



On Fri, Feb 14, 2014 at 1:34 AM, Tom Evans  wrote:

> On Fri, Feb 14, 2014 at 12:38 AM, Javier Guerra Giraldez
>  wrote:
> > On Thu, Feb 13, 2014 at 7:09 PM, Rich Jones  wrote:
> >> We're good now. No idea what the hell was happening, but this works now.
> >> Humbling to realize how little I know about the ORM internals.
> >
> >
> > are you using virtualenv?  it's possible that mod_wsgi was executing
> > in a different environment than the test server.
> >
>
> Or mod_wsgi is compiled for a different version of python and thus is
> finding completely different libraries.
>
> No matter now...
>
> --
> 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/E4UVZHf6kP8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAFHbX1%2ByzgtR8SXh9o5Yh_%2BsyxiPn5b40jR7AD7D2OGMPSNAuA%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

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


Re: FieldError, But Only In Production

2014-02-13 Thread Rich Jones
Said fuck it, gave up and used Nginx + Gunicorn.

We're good now. No idea what the hell was happening, but this works now.
Humbling to realize how little I know about the ORM internals.

Thanks for listening,
R

On Thu, Feb 13, 2014 at 3:13 PM, Rich Jones  wrote:

>
> > Please show how you are doing this.
>
> Using mod_wsgi and Apache, using I think a fairly standard .wsgi:
>
> import os, sys
>
> path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
> if path not in sys.path:
> sys.path.append(path)
>
> sys.path.append('/srv/myapp')
>
> os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
> import django.core.handlers.wsgi
> application = django.core.handlers.wsgi.WSGIHandler()
>
> With this in my sites_enabled:
>
> WSGIScriptAlias / /srv/myapp/myapp/django.wsgi
>
> Also, keep in mind that the application does _run_ with Apache, it is only
> on calls related to user.get_profile() which causes the problem.
>
> Is there anything else you'd need to know?
>
>
> On Thu, Feb 13, 2014 at 3:01 PM, Tom Evans wrote:
>
>> On Thu, Feb 13, 2014 at 6:00 AM, Rich Jones  wrote:
>> > Hey guys!
>> >
>> > I've got a real stumper here. Pulling my hair out over this one, would
>> > really appreciate some options!
>> >
>> > Anywhere in my application that calls user.get_profile() causes a
>> > FieldError.. but only in production. I'm using WSGI and Apache.
>> >
>>
>> Please show how you are doing this.
>>
>> I suspect mod_wsgi might be using a different version of django,
>> perhaps one in the system install.
>>
>> However, that is all just speculative without the config and comparing
>> it with how you start 'runserver'.
>>
>> Cheers
>>
>> Tom
>>
>> --
>> 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/E4UVZHf6kP8/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAFHbX1L%2BhYT32SnOwphBDJzmhpLTHDCe%2BQsA3dWFwwceqyLZHw%40mail.gmail.com
>> .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>

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


Re: FieldError, But Only In Production

2014-02-13 Thread Rich Jones
> Please show how you are doing this.

Using mod_wsgi and Apache, using I think a fairly standard .wsgi:

import os, sys

path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if path not in sys.path:
sys.path.append(path)

sys.path.append('/srv/myapp')

os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

With this in my sites_enabled:

WSGIScriptAlias / /srv/myapp/myapp/django.wsgi

Also, keep in mind that the application does _run_ with Apache, it is only
on calls related to user.get_profile() which causes the problem.

Is there anything else you'd need to know?

On Thu, Feb 13, 2014 at 3:01 PM, Tom Evans  wrote:

> On Thu, Feb 13, 2014 at 6:00 AM, Rich Jones  wrote:
> > Hey guys!
> >
> > I've got a real stumper here. Pulling my hair out over this one, would
> > really appreciate some options!
> >
> > Anywhere in my application that calls user.get_profile() causes a
> > FieldError.. but only in production. I'm using WSGI and Apache.
> >
>
> Please show how you are doing this.
>
> I suspect mod_wsgi might be using a different version of django,
> perhaps one in the system install.
>
> However, that is all just speculative without the config and comparing
> it with how you start 'runserver'.
>
> Cheers
>
> Tom
>
> --
> 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/E4UVZHf6kP8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAFHbX1L%2BhYT32SnOwphBDJzmhpLTHDCe%2BQsA3dWFwwceqyLZHw%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>

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


Re: FieldError, But Only In Production

2014-02-13 Thread Rich Jones
Ah, okay, noted, although I believe this may be a bug in Django itself but
want to exhaust everything before I open a ticket.

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


Re: FieldError, But Only In Production

2014-02-13 Thread Rich Jones
Since this seems to happening at a pretty deep level, would it be uncouth
to kick this over do django-dev?


On Thu, Feb 13, 2014 at 9:17 AM, Rich Jones  wrote:

> Yes, all of these things worked just fine. The code is in the _same
> location_ on the _same machine_ with the _same settings_ and the _same
> database_. The only difference is devserver vs Apache.
>
> :(
>
>
> On Thu, Feb 13, 2014 at 2:21 AM, Vibhu Rishi wrote:
>
>> Seems to me somewhere in the code it is trying to put user into a field
>> instead of treating it as a table.
>> Basic sanity checks :
>> - is the djagno versions on both production and local same ?
>> - same for wsgi and apache ?
>> - syncdb worked fine ?
>>
>> V.
>>
>>
>>
>> On Thu, Feb 13, 2014 at 11:30 AM, Rich Jones  wrote:
>>
>>> Hey guys!
>>>
>>> I've got a real stumper here. Pulling my hair out over this one, would
>>> really appreciate some options!
>>>
>>> Anywhere in my application that calls user.get_profile() causes a
>>> FieldError.. but only in production. I'm using WSGI and Apache.
>>>
>>> When I run locally with:
>>>
>>>  python manage.py runserver 0.0.0.0:
>>>
>>> it works just fine. However, running the exact same code and the exact
>>> same database with Apache, I get a 500 and find this in the logs:
>>>
>>>  [Wed Feb 12 21:23:21 2014] [error] [client] FieldError: Cannot
>>> resolve keyword 'user' into field. Choices are: about_me, about_me_mkd,
>>> etc..
>>>
>>> (Full traceback: http://pastebin.com/6141pHZ2)
>>>
>>> When I run sqlall, there is a users_id entry for the model:
>>>
>>> "user_id" integer NOT NULL UNIQUE REFERENCES "auth_user" ("id")
>>> DEFERRABLE INITIALLY DEFERRED
>>>
>>> What could possibly be happening here? What could the difference between
>>> devserver and Apache?
>>>
>>> (For reference, this is using Django-Userena 1.0, Django 1.3.7. and
>>> Postgres 8.4.)
>>>
>>> I've tried a few things I found on the internet:
>>>
>>>
>>> http://stackoverflow.com/questions/19145787/fielderror-cannot-resolve-keyword--into-field
>>>
>>> http://chase-seibert.github.io/blog/2010/04/30/django-manytomany-error-cannot-resolve-keyword-xxx-into-a-field.html
>>>
>>> Which both suggest that it has something to do with the order of the
>>> imports, but I haven't had any success with this approach.
>>>
>>> There is an extremely old Django bug seemingly related to this,
>>>
>>> https://code.djangoproject.com/ticket/1796
>>>
>>> but I don't know how relevant this is, as this is not a ManyToMany
>>> problem, because Userena uses a OneToOne field:
>>>
>>> user = models.OneToOneField(User,
>>> unique=True,
>>> verbose_name=_('user'),
>>> related_name='profile')
>>>
>>> Can anybody help me? I'm going nuts over here. I just don't know why the
>>> behavior would be different for runserver and Apache!
>>>
>>> Any ideas?
>>>
>>> Thanks so much!,
>>> Rich
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>>
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/41e0fdbe-520d-44a4-b3b5-ee4914d0e099%40googlegroups.com
>>> .
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>>
>>
>> --
>> Simplicity is the ultimate sophistication. - Leonardo da Vinci
>> Life is really simple, but we insist on making it complicated. -
>> Confucius
>>
>> --
>> 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/E4UVZHf6kP8/unsubscribe.
>> To unsubscribe fr

Re: FieldError, But Only In Production

2014-02-13 Thread Rich Jones
Yes, all of these things worked just fine. The code is in the _same
location_ on the _same machine_ with the _same settings_ and the _same
database_. The only difference is devserver vs Apache.

:(


On Thu, Feb 13, 2014 at 2:21 AM, Vibhu Rishi  wrote:

> Seems to me somewhere in the code it is trying to put user into a field
> instead of treating it as a table.
> Basic sanity checks :
> - is the djagno versions on both production and local same ?
> - same for wsgi and apache ?
> - syncdb worked fine ?
>
> V.
>
>
>
> On Thu, Feb 13, 2014 at 11:30 AM, Rich Jones  wrote:
>
>> Hey guys!
>>
>> I've got a real stumper here. Pulling my hair out over this one, would
>> really appreciate some options!
>>
>> Anywhere in my application that calls user.get_profile() causes a
>> FieldError.. but only in production. I'm using WSGI and Apache.
>>
>> When I run locally with:
>>
>>  python manage.py runserver 0.0.0.0:
>>
>> it works just fine. However, running the exact same code and the exact
>> same database with Apache, I get a 500 and find this in the logs:
>>
>>  [Wed Feb 12 21:23:21 2014] [error] [client] FieldError: Cannot
>> resolve keyword 'user' into field. Choices are: about_me, about_me_mkd,
>> etc..
>>
>> (Full traceback: http://pastebin.com/6141pHZ2)
>>
>> When I run sqlall, there is a users_id entry for the model:
>>
>> "user_id" integer NOT NULL UNIQUE REFERENCES "auth_user" ("id")
>> DEFERRABLE INITIALLY DEFERRED
>>
>> What could possibly be happening here? What could the difference between
>> devserver and Apache?
>>
>> (For reference, this is using Django-Userena 1.0, Django 1.3.7. and
>> Postgres 8.4.)
>>
>> I've tried a few things I found on the internet:
>>
>>
>> http://stackoverflow.com/questions/19145787/fielderror-cannot-resolve-keyword--into-field
>>
>> http://chase-seibert.github.io/blog/2010/04/30/django-manytomany-error-cannot-resolve-keyword-xxx-into-a-field.html
>>
>> Which both suggest that it has something to do with the order of the
>> imports, but I haven't had any success with this approach.
>>
>> There is an extremely old Django bug seemingly related to this,
>>
>> https://code.djangoproject.com/ticket/1796
>>
>> but I don't know how relevant this is, as this is not a ManyToMany
>> problem, because Userena uses a OneToOne field:
>>
>> user = models.OneToOneField(User,
>> unique=True,
>> verbose_name=_('user'),
>> related_name='profile')
>>
>> Can anybody help me? I'm going nuts over here. I just don't know why the
>> behavior would be different for runserver and Apache!
>>
>> Any ideas?
>>
>> Thanks so much!,
>> Rich
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>>
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/41e0fdbe-520d-44a4-b3b5-ee4914d0e099%40googlegroups.com
>> .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>
>
> --
> Simplicity is the ultimate sophistication. - Leonardo da Vinci
> Life is really simple, but we insist on making it complicated. - Confucius
>
> --
> 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/E4UVZHf6kP8/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPiONw%3DwazFkycVy%3DAwoj99uq4RgqhFu%2B2iotZz712AKa0U%3DYQ%40mail.gmail.com
> .
>
> For more options, visit https://groups.google.com/groups/opt_out.
>

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


FieldError, But Only In Production

2014-02-12 Thread Rich Jones
Hey guys!

I've got a real stumper here. Pulling my hair out over this one, would 
really appreciate some options!

Anywhere in my application that calls user.get_profile() causes a 
FieldError.. but only in production. I'm using WSGI and Apache.

When I run locally with:

 python manage.py runserver 0.0.0.0:

it works just fine. However, running the exact same code and the exact same 
database with Apache, I get a 500 and find this in the logs:

 [Wed Feb 12 21:23:21 2014] [error] [client] FieldError: Cannot resolve 
keyword 'user' into field. Choices are: about_me, about_me_mkd, etc..

(Full traceback: http://pastebin.com/6141pHZ2)

When I run sqlall, there is a users_id entry for the model:

"user_id" integer NOT NULL UNIQUE REFERENCES "auth_user" ("id") 
DEFERRABLE INITIALLY DEFERRED

What could possibly be happening here? What could the difference between 
devserver and Apache?

(For reference, this is using Django-Userena 1.0, Django 1.3.7. and 
Postgres 8.4.)

I've tried a few things I found on the internet:

http://stackoverflow.com/questions/19145787/fielderror-cannot-resolve-keyword--into-field
http://chase-seibert.github.io/blog/2010/04/30/django-manytomany-error-cannot-resolve-keyword-xxx-into-a-field.html

Which both suggest that it has something to do with the order of the 
imports, but I haven't had any success with this approach.

There is an extremely old Django bug seemingly related to this,

https://code.djangoproject.com/ticket/1796

but I don't know how relevant this is, as this is not a ManyToMany problem, 
because Userena uses a OneToOne field:

user = models.OneToOneField(User,
unique=True,
verbose_name=_('user'),
related_name='profile')

Can anybody help me? I'm going nuts over here. I just don't know why the 
behavior would be different for runserver and Apache! 

Any ideas?

Thanks so much!,
Rich 

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


Re: New Feature

2013-10-12 Thread Rich Haase
As with all software the best solutions are written to solve a problem that 
bugs the developer.  Find something that you find troublesome on a regular 
basis, then code a solution.

Sent from my iPhone

> On Oct 12, 2013, at 12:26 AM, jasvir singh  
> wrote:
> 
> Hello everyone.
> 
> I am new to this mailing list, but have a long relationship with django.
> I want to add something new to django, a new package to django.
> Please suggest me to do something creative. 
> Previously I was thinking to create a package to embed youtube videos, but 
> packages for same already exist. Same thing happened with chatting package.
> I want to create a new package.
> Please suggest me something.
> -- 
> Mr. Singh
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CANJu%3DjFHGjVp%3Dv05zz4XJuRp9rFccSHg8wRcDAkpDMU1RKX6bw%40mail.gmail.com.
> For more options, visit https://groups.google.com/groups/opt_out.

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


Re: Reliable and cheap hosting for simple webapp in Django

2013-09-10 Thread Rich Haase
Try one of the following:

Gondor
GoogleApp Engine
Heroku


On Tue, Sep 10, 2013 at 3:55 PM, Andre Lopes  wrote:

> Hi all,
>
> I'm stuck with Django hosting. I've A2hosting but the Django hosting
> is not good at all.
>
> They use FCGI and Passenger and both have a problem.
>
> If I'm more than 15min without doing a request to the site, the first
> request is very slow and most of the time will do an Internal Server
> Error.
>
> There is any Django hosting on the cheap that works without this kind
> of problems? The website have 5/10 visits a day.
>
> I wait for reply.
>
> Best Regards,
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
*Kernighan's Law*
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it."

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


Re: JSON or YAML?

2013-08-30 Thread Rich Haase
Personal preference.  Python has excellent libraries to support parsing both 
JSON and YAML.

Sent from my iPhone

On Aug 30, 2013, at 7:34 AM, Floor Tile  wrote:

> Helle everybody,
> 
> Just a short and simple question:
> 
> It seams that both JSON and YAML can be used for initial data loading. (among 
> other data types but I don't care about them for the moment)
> But can't figure out what the up and/or downsides of them are.
> Is it purely a matter of personal preference or there one better to use than 
> the other for initial data loading. And which one would be the most 
> preferred, if this is the case?
> 
> Many thanks in advance!
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.

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


Re: Any Tutorials on Django similar to Web2py ????????????????

2013-08-20 Thread Rich Haase
I second the book recommendation.  I had a cursory knowledge of django
(enough to get myself in trouble) prior to reading 2 scoops of django.  Now
I have enough knowledge to really make a mess... j/k.  It's a great book
for learning about the nitty gritty of django development and informing the
questions you will ask.

Cheers,

rich


On Tue, Aug 20, 2013 at 12:48 PM, Sergio Infante Montero <
raulserg...@gmail.com> wrote:

> Maybe, you need some book like this
>
> https://django.2scoops.org/
>
> Regards
>
> On Tue, Aug 20, 2013 at 11:21 AM, Marcos Moyano 
> wrote:
> > There are several ways to manage sessions, or cache. That's up to you
> > according to your needs.
> > You can find documentation about sessions, caching and much more here:
> > https://docs.djangoproject.com/en/1.5/
> >
> > Rgds
> >
> >
> > On Tue, Aug 20, 2013 at 1:12 PM, JAI PRAKASH SINGH
> >  wrote:
> >>
> >> Thank you sir, but i need that kind of tutorials which is complete , in
> >> terms of security, session, cache like udacity  tutorilas on web2py ..
> on
> >> web development.
> >>
> >> Please revert back if u have any kind of link on it
> >>
> >>
> >> On Tue, Aug 20, 2013 at 9:35 PM, carlos  wrote:
> >>>
> >>> https://docs.djangoproject.com/en/1.5/intro/tutorial01/
> >>>
> >>> Cheers
> >>>
> >>>
> >>> On Tue, Aug 20, 2013 at 9:57 AM, JAI PRAKASH SINGH
> >>>  wrote:
> >>>>
> >>>> Any Tutorials on Django similar to Web2py 
> >>>>
> >>>> --
> >>>> You received this message because you are subscribed to the Google
> >>>> Groups "Django users" group.
> >>>> To unsubscribe from this group and stop receiving emails from it, send
> >>>> an email to django-users+unsubscr...@googlegroups.com.
> >>>>
> >>>> To post to this group, send email to django-users@googlegroups.com.
> >>>> Visit this group at http://groups.google.com/group/django-users.
> >>>> For more options, visit https://groups.google.com/groups/opt_out.
> >>>
> >>>
> >>> --
> >>> You received this message because you are subscribed to a topic in the
> >>> Google Groups "Django users" group.
> >>> To unsubscribe from this topic, visit
> >>> https://groups.google.com/d/topic/django-users/8i61qvs2tn4/unsubscribe
> .
> >>> To unsubscribe from this group and all its topics, send an email to
> >>> django-users+unsubscr...@googlegroups.com.
> >>>
> >>> To post to this group, send email to django-users@googlegroups.com.
> >>> Visit this group at http://groups.google.com/group/django-users.
> >>> For more options, visit https://groups.google.com/groups/opt_out.
> >>
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> Groups
> >> "Django users" group.
> >> To unsubscribe from this group and stop receiving emails from it, send
> an
> >> email to django-users+unsubscr...@googlegroups.com.
> >> To post to this group, send email to django-users@googlegroups.com.
> >> Visit this group at http://groups.google.com/group/django-users.
> >> For more options, visit https://groups.google.com/groups/opt_out.
> >
> >
> >
> >
> > --
> > Some people, when confronted with a problem, think “I know, I'll use
> regular
> > expressions.” Now they have two problems.
> >
> > Jamie Zawinski, in comp.emacs.xemacs
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to django-users+unsubscr...@googlegroups.com.
> > To post to this group, send email to django-users@googlegroups.com.
> > Visit this group at http://groups.google.com/group/django-users.
> > For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
> --
> Sergio Infante Montero
> http://about.me/neosergio
> @neosergio
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
*Kernighan's Law*
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it."

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


Re: templates not updating when i change things please help

2012-02-19 Thread Rich
I found my problem... I had 2 different templates created with the
same code and I was using the wrong one

On Feb 19, 9:53 am, Rich  wrote:
> Hi I am pretty new to django and I feel like I either have some kind
> of configuration wrong or maybe im not understanding how something
> works.
>
> Whats happening is when I make a small change in one of my templates,
> the change is not reflected on my site.
>
> I have noticed that if I make significant changes in one of my views,
> I might see an update in the actual website after reloading the page
> (but it seems to be hit or miss)
>
> If I make only a small change, there is almost never an update to the
> actual website unless it is a change within a view.
>
> Changing some text within a template file yields no results.
>
> If I mess up some code i will get debugging messages, but if I fix the
> code, I get the same (cached?) result

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



templates not updating when i change things please help

2012-02-19 Thread Rich
Hi I am pretty new to django and I feel like I either have some kind
of configuration wrong or maybe im not understanding how something
works.

Whats happening is when I make a small change in one of my templates,
the change is not reflected on my site.

I have noticed that if I make significant changes in one of my views,
I might see an update in the actual website after reloading the page
(but it seems to be hit or miss)

If I make only a small change, there is almost never an update to the
actual website unless it is a change within a view.

Changing some text within a template file yields no results.

If I mess up some code i will get debugging messages, but if I fix the
code, I get the same (cached?) result

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



Deverifying a URLField

2012-01-24 Thread Rich Jones
Hello, all!

I have a small conundrum I could use a hand with.

I have a deployed Django application with a Model which has a
URLField:

project_homepage = models.URLField('Project Homepage', blank=True)

and a ModelForm to create the parent object.

Currently, the application checks to see if this is a valid URL. I
would like this to be unvalidated instead.

How do I go about changing it? Will I need to do a database migration
to do this? Or can I just add a 'verified=False' and run syncdb?

Thanks so much!
Rich

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



IOError: request data read error

2011-11-21 Thread Rich Jones
Uh-oh, some of you are saying, not this one again!..

I've read all of the posts on this error that I could find, but I'm
still not finding anything useful. Can somebody please explain what
this error is all about? It happens only on the POST requests to one
of my pages. It isn't a page which has an image upload, only text.

This is Python 2.6, modwsgi 2.8-2ubuntu1, and Django 1.3.

What's going on? Is it really some user just cancelling during the
POST over and over again? Does it have to do with server load? My
apache settings?

I can provide full trace if it will be useful.

Thanks so much!
Rich

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



Earn 25$ to add Email Notification support to Django-Userena

2011-10-05 Thread Rich Jones
Hey all!

I've opened a 25$ gig on Gun.io to add Email Notification support to
Django-Userena. First person to get a pull request accepted will earn
the money!

http://gun.io/open/11/add-email-notifcations-to-django-userena-umessages

Thought you guys might be interested in earning a quick bit of money
to work on an open source project.

Rich

-- 
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: What are the advantages of Model inheritance?

2011-06-23 Thread Rich Jones
Even ignoring the select_related then - the fact is that

user.post_set works and user.betterpost_set won't work, seemingly as
the result of using model inheritance.

Perhaps I could get all of the posts (post and betterposts) and then
filter by time? Does that make sense / is there a way to do that in
the template?

R

On Jun 23, 5:40 pm, Micky Hulse  wrote:
> On Thu, Jun 23, 2011 at 2:17 PM, bruno desthuilliers
>
>  wrote:
> > FWIW, I have been using model inheritance - abstract and concrete - in
> > half a dozen projects, with about 30 model subclasses in one of them,
> > and it JustWorks(tm).
>
> That sounds pretty sweet! :D
>
> I would love to see some examples.
>
> I have been using abstract models for some of my projects... I find
> them extremely useful:
>
> https://gist.github.com/1043698
>
> It works for me... Of course, I am still a noobie to Python/Django, so
> may the feedback be kind. :: crosses fingers :: :D

-- 
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: What are the advantages of Model inheritance?

2011-06-23 Thread Rich Jones
Where would _meta need to go?

This code does appear to work the way I am describing it, this is just
a slightly stripped down of a real application I have made.

R

On Jun 23, 4:59 pm, "Cal Leeming [Simplicity Media Ltd]"
 wrote:
> I might be wrong here, but I'm fairly sure that the below example you pasted 
> is invalid code (i.e. you need to add a proxy _meta??).
> My apologies if I'm wrong though, as I have never encountered a need to do 
> this before, and just going off vague memory.
> Cal
> On 23/06/2011 19:24, Rich Jones wrote:Other than the convenience of writing 
> them, I can't seem to find any advantages of using model inheritance. Please 
> allow me to explain the trouble I am having with an example. Suppose, class 
> Post(models.Model): title = models.CharField(max_length=200) user_owner_id = 
> models.ForeignKey(User) def __unicode__(self): return self.title class 
> BetterPost(Post): description = models.CharField(max_length=200) def 
> __unicode__(self): return self.title Now, in the template: {% with 
> profile.user.post_set.select_related as posts %} {% for post in posts %} 
> {{post}} {% empty %} No posts! {% endfor %} {% endwith %} {% with 
> profile.user.betterpost_set.select_related as posts %} {% for post in posts 
> %} {{post}} {% empty %} No posts! {% endfor %} {% endwith %} If there are 2 
> 'Posts' and 1 'BetterPost', the template code will print all of the posts in 
> the first loop, then none in the second loop set. So why would I use model 
> inheritance if this is the kind of behavior I can expect? If I can't get a 
> set and can't access the fields, why wouldn't I just copy the fields into 
> BetterPost rather than extending Post? Thank you for reading! R

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



What are the advantages of Model inheritance?

2011-06-23 Thread Rich Jones
Other than the convenience of writing them, I can't seem to find any
advantages of using model inheritance.

Please allow me to explain the trouble I am having with an example.
Suppose,

class Post(models.Model):
title = models.CharField(max_length=200)
user_owner_id = models.ForeignKey(User)

def __unicode__(self):
return self.title

class BetterPost(Post):
description = models.CharField(max_length=200)

def __unicode__(self):
return self.title

Now, in the template:

{% with profile.user.post_set.select_related as posts %}
{% for post in posts %}
{{post}}
{% empty %}
No posts!
{% endfor %}
{% endwith %}

{% with profile.user.betterpost_set.select_related as posts %}
{% for post in posts %}
{{post}}
{% empty %}
No posts!
{% endfor %}
{% endwith %}

If there are 2 'Posts' and 1 'BetterPost', the template code will
print all of the posts in the first loop, then none in the second loop
set.

So why would I use model inheritance if this is the kind of behavior I
can expect? If I can't get a set and can't access the fields, why
wouldn't I just copy the fields into BetterPost rather than extending
Post?

Thank you for reading!
R

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



Midlands Django Jedi needed

2011-06-20 Thread Rich Catley
Dear all

We have an opening for a Django/Python developer. Role is based in the
Midlands, UK. Great environment, great team. Get in contact for more
details.

Thanks
Rich

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



Django password reset modification

2011-05-05 Thread Rich
Django framework comes with a reset password out of the box feature.
I would like to modify this to where a password is sent to the user
via e-mail. I looked at the code in django\contib\auth\views.py
I'm not sure how I can modify it.




Django Reset Password

The Django framework comes with support for resetting user passwords.
This is implemented for the Admin app, but it is possible to re-use
from your own screens.
URLs

The following four URLs are used in the password reset

(r'^accounts/password/reset/$',
'django.contrib.auth.views.password_reset',
{'post_reset_redirect' : '/accounts/password/reset/done/'}),
(r'^accounts/password/reset/done/$',
'django.contrib.auth.views.password_reset_done'),
(r'^accounts/password/reset/(?P[0-9A-Za-z]+)-(?P.+)/$',
'django.contrib.auth.views.password_reset_confirm',
{'post_reset_redirect' : '/accounts/password/done/'}),
(r'^accounts/password/done/$',
'django.contrib.auth.views.password_reset_complete'),

Templates

The following five templates are required. These are the templates for
the four urls pointed to from the urlpatterns above, plus one template
for the email.

* registration/password_reset_complete.html
* registration/password_reset_confirm.html
* registration/password_reset_done.html
* registration/password_reset_form.html
* registration/password_reset_email.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.



  1   2   >