Adding admin access for external users

2015-03-27 Thread Murthy Sandeep
Hi

I am setting up an admin user account to manage my Django app on
my local machine, but would it be possible for me to also give admin
access to external users using their own machines?  My machine is
not part of a LAN/WAN, just standalone, but I am thinking that to enable
this I should provide the admin URL to another external user and then
allow remote login access for them.


-- 
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/E934EE83-6B33-4307-BF61-506A364698AB%40sandeepmurthy.is.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Message signed with OpenPGP using GPGMail


Data migration script populating db table - testing

2015-03-22 Thread Murthy Sandeep
Hi

I have created an data migration script for populating one of
app db tables with data from a JSON file.  First I ran

python manage.py makemigrations --empty TPP_App



(‘TPP_App’ is the name of my app) and then I added a custom
method called populate_db which will use bulk_create to add
multiple entries to the table, and then do a save() to write the
changes to the db.  At the moment the custom method is empty
because I am still working on it, but the script looks like this right
now

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations

def populate_db( apps, schema_editor ):
print ‘Populating db from JSON file...'

class Migration(migrations.Migration):

dependencies = [
('TPP_App', '0003_auto_20150224_2024'),
]

operations = [
   migrations.RunPython( populate_db ),
]

How do I test this script to make sure the custom method works
as expected, before I run it fully?  Can I call this from the interpreter
and test it with the db API?

At the moment if I do

python manage.py migrate

it reports there are no migrations to apply.

Sandeep


-- 
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/10767D81-937A-4F08-983A-B055C4AB3982%40sandeepmurthy.is.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: Data migration using RunPython

2015-03-05 Thread Murthy Sandeep
Thanks,

Two further questions if you don’t mind:

1. I am in the Python interpreter and am working with
one of my db models called SmallGroup.

When I do SmallGroup.objects.all() I get the following message:

File "", line 1, in 
  File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 119, 
in __repr__
return repr(data)
  File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 458, 
in __repr__
u = six.text_type(self)
TypeError: coercing to Unicode: need string or buffer, SmallGroup found

Does this have something to do with the method `__str__` which I added
to this model in my `models.py`?  I don’t think I did a ‘python manage.py 
migrate’ after
the change though.

2. If I want to modify or delete entries in the db table SmallGroup are there
methods corresponding to `bulk_create` for doing this?  Something like

Country.objects.using(db_alias).bulk_update(  )

Country.objects.using(db_alias).bulk_delete(  )

?

Thanks again in advance.

Sandeep

> On 5 Mar 2015, at 19:34, aRkadeFR <cont...@arkade.info> wrote:
> 
> Hello,
> 
> In Django, you can instanciate objects from your model without
> persist it to the database. The way you do it is Country(name=..., ...).
> 
> In order to create multiple objects at once, you can
> call the bulk_create method on the manager with a list
> of object to persist.
> 
> The using(db_alias) is instanciating the manager.
> I won't explain further cause my knowledge of this area
> is reduced.
> 
> Have a good one
> 
> On 03/05/2015 01:20 AM, Murthy Sandeep wrote:
>> I am working on a data migration for my Django app to populate
>> the main table in the db with data that will form the mainstay of
>> the app - this is persistent/permanent data that may added to but
>> never deleted.
>> 
>> My reference is the Django 1.7 documentation and in particular an
>> example on page
>> 
>> https://docs.djangoproject.com/en/1.7/ref/migration-operations/#django.db.migrations.operations.RunPython
>> 
>> with a custom method called forward_funcs:
>> 
>> def forwards_func(apps, schema_editor):
>> 
>> # We get the model from the versioned app registry;
>> # if we directly import it, it'll be the wrong version
>> 
>> 
>> Country = apps.get_model("myapp", "Country")
>> db_alias = schema_editor.connection.alias
>> Country.objects.using(db_alias).bulk_create([
>> Country(name="USA", code="us"),
>> Country(name="France", code="fr"),])
>> 
>> I was wondering if someone could please explain what is happening
>> here and how this method works - is the argument  to bulk_create a
>> list of namedtuple objects called Country or are these Country model
>> objects?
>> 
>> Also could someone please explain what db_alias is?
>> 
>> Sandeep
>> 
>> 
> 
> --
> 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/54F814FC.9090407%40arkade.info.
> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/FB970506-5557-4EC1-90C2-A5918C36FC3F%40sandeepmurthy.is.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Message signed with OpenPGP using GPGMail


Data migration using RunPython

2015-03-04 Thread Murthy Sandeep
I am working on a data migration for my Django app to populate
the main table in the db with data that will form the mainstay of
the app - this is persistent/permanent data that may added to but
never deleted.

My reference is the Django 1.7 documentation and in particular an
example on page

https://docs.djangoproject.com/en/1.7/ref/migration-operations/#django.db.migrations.operations.RunPython

with a custom method called forward_funcs:

def forwards_func(apps, schema_editor):

# We get the model from the versioned app registry;
# if we directly import it, it'll be the wrong version


Country = apps.get_model("myapp", "Country")
db_alias = schema_editor.connection.alias
Country.objects.using(db_alias).bulk_create([
Country(name="USA", code="us"),
Country(name="France", code="fr"),])

I was wondering if someone could please explain what is happening
here and how this method works - is the argument  to bulk_create a
list of namedtuple objects called Country or are these Country model
objects?

Also could someone please explain what db_alias is?

Sandeep


-- 
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/79F2F719-8483-46A6-8DC2-94E6C937CAA8%40sandeepmurthy.is.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: Populating Django app db with JSON data

2015-03-04 Thread Murthy Sandeep
Hi

thanks for the info.

The docs also say that RunPython runs “custom Python code
in a historical context”.  What does that mean exactly?  It seems
related to the apps and schema_editor arguments passed to
the custom method that will be called by RunPython - is this something
like a snapshot of the app model that is stored when I do `python manage.py 
migrate`?

Sandeep


> On 2 Mar 2015, at 19:37, aRkadeFR  wrote:
> 
> Hello,
> 
> Indeed, the data migration is the best way. Check out
> the documentation here:
> https://docs.djangoproject.com/en/1.7/ref/migration-operations/#django.db.migrations.operations.RunPython
> 
> You write your function that will be called by the RunPython
> and will load your JSON.
> Migration are ordered, your first migration will create the
> tables and the second (your data migration) will load your
> JSON.
> 
> To create an empty migration:
> ./manage.py makemigrations  --empty
> 
> You can rename to a useful descriptive name the migration
> file.
> 
> Have a good one
> 
> 
> On 03/02/2015 08:16 AM, Sandeep Murthy wrote:
>> Hi
>> 
>> I've tried to get the answer to this question (which is a bit open-ended) on 
>> stackoverflow without much success, which
>> is basically this: what is the recommended approach to populating a 
>> pre-existing Django app database table (generated
>> from a model and which is currently empty) with JSON data?
>> 
>> There seem to be several alternatives given in the Django documentation 
>> (Django 1.7 manual) which include (1) fixtures,
>> (2) SQL scripts, (3) data migrations.  Of these I am a bit confused by the 
>> advice in the manual which suggests that (1)
>> and (2) are only useful for loading initial data.  That's not what I want to 
>> do.  The data that the app needs is going to be
>> persistent and permanent because the app is intended to be a web query tool 
>> for a large dataset that is currently in the
>> form of several JSON files, each containing on average thousands of JSON 
>> objects, each object representing an entry
>> corresponding to a table entry in a relational db.  The data is not going to 
>> be re-loaded or change after entry, and there
>> is no user facility for changing the data.
>> 
>> The table has been created using the makemigrations and migrate tools, but 
>> is empty.  I just need to populate the
>> table with the JSON data.  It seems that I need to write a custom data 
>> migration script that will insert the data into the
>> table via the interpreter, and then I need to run python manage.py migrate.  
>> Is this the case, and if so, are there
>> are examples that I could use?
>> 
>> Thanks in advance for any suggestions.
>> 
>> SM
>> --
>> 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/db5919c5-ace4-4556-b90e-aa47baa26552%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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/54F42164.6040505%40arkade.info.
> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/279E5DB5-57C9-4A85-9EDA-3A9159BE8925%40sandeepmurthy.is.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Message signed with OpenPGP using GPGMail