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.


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


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, 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 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-16 Thread Rich Shepard

On Tue, 16 Aug 2016, Avraham Serour wrote:


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


  Thanks, Avraham. Looks interesting.

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


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



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


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



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


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:


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


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


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


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


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



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


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


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


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


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


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


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


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


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


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



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


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


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


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


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




Pre-loading static data into database table

2017-06-29 Thread Rich Shepard

  Reading

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


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


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




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