Re: self.foreign_related_fields[0] IndexError: tuple index out of range

2019-11-25 Thread Integr@te System
Hi man,

Check 'class UserManager(): ..orgid = org_obj '




On Tue, Nov 26, 2019, 01:40 Ahmad Saki  wrote:

> My custom authentication model in django:
>
> from django.db import models
> from django.contrib.auth.models import (
> AbstractBaseUser, BaseUserManager
> )
> from organization.models import Organization
>
>
> class UserManager(BaseUserManager):
> # use_in_migrations = True
>
> # python manage.py createsuperuser
> def create_user(self, orgid, username, email,  password=None, is_admin=False, 
> is_staff=False, is_active=True):
> if not orgid:
> raise ValueError("Organization of user must not empty")
> elif not username:
> raise ValueError("User must have an username")
> elif not email:
> raise ValueError("User must have an email address")
>
> org_obj = Organization.objects.all(orgid=orgid)
> user_obj = self.model(
> orgid=org_obj,
> username=username,
> email = self.normalize_email(email),
> password=password
> )
> user_obj.set_password(password)
> user_obj.admin=is_admin
> user_obj.staff=is_staff
> user_obj.active=is_active
> user_obj.save(using=self._db)
> return user_obj
>
> # python manage.py createsuperuser
> def create_superuser(self, orgid, username, email, password=None):
> user = 
> self.create_user(orgid,username,email,password=password,is_admin=True,is_staff=True,is_active=True)
> return user
>
> def create_staffuser(self, orgid, username, email, password=None):
> user = 
> self.create_user(orgid,username,email,password=password,is_admin=False,is_staff=True,is_active=True)
> return user
>
> class User(AbstractBaseUser):
> orgid   = models.ForeignKey(Organization, max_length=6, 
> on_delete=models.CASCADE)
> username= models.CharField(primary_key=True, max_length=50)
> email   = models.EmailField(max_length=255, unique=True, null=False, 
> blank=False)
> admin   = models.BooleanField(default=False)
> staff   = models.BooleanField(default=False)
> active  = models.BooleanField(default=True)
> date_joined = models.DateTimeField(auto_now_add=True)
>
> objects = UserManager()
>
> USERNAME_FIELD = "username"
> # REQUIRED_FIELDS must contain all required fields on your User model,
> # but should not contain the USERNAME_FIELD or password as these fields will 
> always be prompted for.
> REQUIRED_FIELDS = ['orgid','email']
>
> class Meta:
> app_label = "user"
> db_table = "user"
>
> def __str__(self):
> return self.username
>
> def get_full_name(self):
> return self.username
>
> def get_short_name(self):
> return self.username
>
> # this methods are require to login super user from admin panel
> def has_perm(self, perm, obj=None):
> return self.is_staff
>
> # this methods are require to login super user from admin panel
> def has_module_perms(self, app_label):
> return self.is_staff
>
> @property
> def is_admin(self):
> return self.admin
>
> @property
> def is_staff(self):
> return self.staff
>
> @property
> def is_active(self):
> return self.active
>
>
>
> When I create migrations it creates:
>
> from django.db import migrations, models
> import django.db.models.deletion
> import user.models
>
>
> class Migration(migrations.Migration):
>
> initial = True
>
> dependencies = [
> ('organization', '0001_initial'),
> ]
>
> operations = [
> migrations.CreateModel(
> name='User',
> fields=[
> ('password', models.CharField(max_length=128, 
> verbose_name='password')),
> ('last_login', models.DateTimeField(blank=True, null=True, 
> verbose_name='last login')),
> ('username', models.CharField(max_length=50, primary_key=True, 
> serialize=False)),
> ('email', models.EmailField(max_length=255, unique=True)),
> ('admin', models.BooleanField(default=False)),
> ('staff', models.BooleanField(default=False)),
> ('active', models.BooleanField(default=True)),
> ('date_joined', models.DateTimeField(auto_now_add=True)),
> ('orgid', models.ForeignKey(max_length=6, 
> on_delete=django.db.models.deletion.CASCADE, to='organization.Organization')),
> ],
> options={
> 'db_table': 'user',
> },
> managers=[
> ('objects', user.models.UserManager()),
> ],
> ),
> ]
>
>
>
> But when I want to migrate it gives me an error below. Please help me
> anyone..
>
> Operations to perform:
>   Apply all migrations: admin, auth, contenttypes, organization, sessions, 
> user
> Running migrations:
>   Applying admin.0004_auto_20191118_2315...Traceback (most recent call last):
>   File "manage.py", line 21, in 
> main()
>   File "manage.py", line 17, in main
> execute_from_command_line(sys.argv)
>   File 
> "C:\Users\ZAB-SAKI\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py",
>  line 381, in execute_fr

Re: Session backend for production

2019-11-25 Thread Parth Joshi
Cache implementation will be definitely use faster if you are using MVT. If 
using REST (DRF) then token Auth definitely helps.


Regards, 

Parth Joshi



> On 26-Nov-2019, at 2:41 AM, Lorenzo Peña  wrote:
> 
> Hello, fellow djangonauts!
> 
> Is there any particular reason why should I pick memcached backed sessions in 
> production over db, or viceversa? Most documentation seems to slightly 
> suggest that memcached should perform faster than database. Any other 
> criteria I should be aware of? I am using single database for multi-tenant 
> application, so I am expecting over-average db traffic.
> 
> Thanks in advance!
> Lorenzo
> 
> -- 
> 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/ac9c9ede-86bf-4136-8bc1-91137e80e9ef%40googlegroups.com
>  
> .

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9281659D-BE57-40BC-9D10-C687E489334E%40gmail.com.


Re: Customer specific translations

2019-11-25 Thread Mike Dewhirst

On 25/11/2019 11:11 pm, Jani Tiainen wrote:
I've use-case where my django app is delivered to multiple customers 
in multiple languages.


Due the nature of application end users do use for certain terms their 
own wording, which differ significantly from others.


For example:

"Delivery route". Some may call it "driving route". Some "route" and 
some just "delivery route".


I love this. It means the customers are involved and taking ownership. I 
think it is worthwhile making it a feature of all/most apps. It could 
even be built into Django one day.


It probably means building a special app to let customers enter their 
own terms for certain fields. The app would need to store such terms in 
the database or ini files. Not sure how you might do it but I'd probably 
look at overriding verbose_name. Might bypass the usual translations 
because the customer probably supplies the correct language as well.


def get_verbose_name(obj, field=None):

    if field is None:

    return obj.__class__()._meta.verbose_name

    try:

    return obj.__class__()._meta.get_field("{0}".format(field)).verbose_name

    except FieldDoesNotExist:

    return None



It needs to include drop-down lists too.

def choose(choices, choice):

    # this demands that choices is exactly as Django specifies

    for pair in choices:

    if pair[0] == choice:

    return pair[1]

    for option in choices:

    for pair in option[1]:

    if pair[0] == choice:

    return pair[1]



Please keep us posted with your solution. It is a brilliant use-case.

Cheers

Mike



Any ideas how to handle this?

--
Jani Tiainen
Software wizard

https://blog.jani.tiainen.cc/

Always open for short term jobs or contracts to work with Django.
--
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/CAHn91odVXDb_Tu3pAmmKtZMNZZyLDzHak9WMmMxU6HZrY0v_Zg%40mail.gmail.com 
.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/85d9ba45-1a2c-0a6c-3b12-e67463ba8ba2%40dewhirst.com.au.


Re: Trying to update a record using UpdateView Error: Circuitinfotable matching query does not exist

2019-11-25 Thread Gil Obradors
Hi!
Matching query doesn't exists says that this entry with this id not exists
in db
Are you sure that this object exists? STTK-100G-18040-01-WRBB

Can you open a shell and:

from xxx.models import Circuitinfotable
obj = Circuitinfotable.objects.all()
print(len(obj))
obj = Obj.get(circuitid='STTK-100G-18040-01-WRBB')
print(obj)


Are you following me?
Or confirm that exists via admin?




Missatge de Patrick Carra  del dia dl., 25 de nov.
2019 a les 22:37:

> Sorry I forgot one! My models.py for this class is below:
>
> class Circuitinfotable(models.Model):
>id1 = models.IntegerField(blank=True, null=True)
>pid = models.CharField(max_length=255, blank=True, null=True)
>circuitid = models.CharField(primary_key=True, max_length=255, blank=
> False, null=False)
>bandwidth = models.CharField(max_length=255, blank=True, null=True)
>region = models.CharField(max_length=255, blank=True, null=True)
>bw = models.IntegerField(blank=True, null=True)
>tableaupathname = models.CharField(max_length=255, blank=True, null=
> True)
>handoffalocaddress = models.CharField(max_length=255, blank=True, null=
> True)
>handoffaloccity = models.CharField(max_length=255, blank=True, null=
> True)
>handoffalocst = models.CharField(max_length=255, blank=True, null=True)
>alocationaddress = models.CharField(max_length=255, blank=True, null=
> True)
>alocationcity = models.CharField(max_length=255, blank=True, null=True)
>alocst = models.CharField(max_length=255, blank=True, null=True)
>handoffzlocaddress = models.CharField(max_length=255, blank=True, null=
> True)
>carrier = models.CharField(max_length=255, blank=True, null=True)
>handoffzloccity = models.CharField(max_length=255, blank=True, null=
> True)
>handoffzlocst = models.CharField(max_length=255, blank=True, null=True)
>zlocationaddress = models.CharField(max_length=255, blank=True, null=
> True)
>zlocationcity = models.CharField(max_length=255, blank=True, null=True)
>zlocst = models.CharField(max_length=255, blank=True, null=True)
>segmentid = models.CharField(max_length=255, blank=True, null=True)
>segmenttype = models.CharField(max_length=255, blank=True, null=True)
>status = models.CharField(max_length=255, blank=True, null=True)
>purpose = models.CharField(max_length=255, blank=True, null=True)
>installdate = models.DateField(blank=True, null=True)
>termdate = models.DateField(blank=True, null=True)
>termlengthmos = models.IntegerField(blank=True, null=True)
>legacy = models.CharField(max_length=255, blank=True, null=True)
>installciopsticket = models.CharField(max_length=255, blank=True, null=
> True)
>retermciopsticket = models.CharField(max_length=255, blank=True, null=
> True)
>discociopsticket = models.CharField(max_length=255, blank=True, null=
> True)
>notes = models.CharField(max_length=255, blank=True, null=True)
>kma = models.CharField(max_length=255, blank=True, null=True)
>group = models.IntegerField(blank=True, null=True)
>cktidkey = models.IntegerField(blank=True, null=True)
>visiolink = models.CharField(max_length=255, blank=True, null=True)
>latestjiraticket = models.CharField(max_length=255, blank=True, null=
> True, unique=True)
>disconnectdate = models.DateField(blank=True, null=True)
>segmentname = models.CharField(max_length=255, blank=True, null=True)
>mrcnew = models.TextField(blank=True, null=True)  # This field type is
> a guess.
>termyrs = models.IntegerField(blank=True, null=True)
>monthbudget = models.IntegerField(blank=True, null=True)
>monthdisco = models.IntegerField(blank=True, null=True)
>mrcold = models.TextField(blank=True, null=True)  # This field type is
> a guess.
>kmz = models.CharField(max_length=255, blank=True, null=True)
>
> class Meta:
>managed = False
>db_table = 'circuitinfotable'
>
> def __str__(self):
>return self.circuitid
>
> def get_absolute_url(self):
>return reverse('home')
>
>
>
> --
> 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/b407aac9-aec7-4e45-b91a-9864c4be2d80%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK-JoTRKYihP_1DAqOudi5dHfGb5b0pi3%3DtBM04yOZ7-6OoRgA%40mail.gmail.com.


Re: Django on an existing PostgreSQL Database?

2019-11-25 Thread carlos
https://docs.djangoproject.com/en/2.2/howto/legacy-databases/

On Mon, Nov 25, 2019 at 3:03 PM Ulrich Goebel  wrote:

> Hi,
>
> I have an existing PostgreSQL Database with about 20 tables, using
> collating sequences, foreign keys, triggers, and even additional indexes.
> For that database I want to write a WEB-frontend to insert, update and
> delete data in the database. I don't want to define the data model in
> python or django, but want to make django/python work on the existing
> database.
>
> Is that possible? Where to find som helpful hints how to do that?
>
> Best regards
> Ulrich
>
> --
> 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/a923c993-d03e-42cd-904f-3eabe811429b%40googlegroups.com
> 
> .
>


-- 
att.
Carlos Rocha

-- 
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/CAM-7rO1MLMEgkuU8GsY3wz3ZsO5WzpwOdp-XHGqp6Zu8maaf8Q%40mail.gmail.com.


Re: How to migrate Django site from MySQL database to Postgres?

2019-11-25 Thread carlos
1. Install your application on the server first, if you have media files,
then copy them from your localhost to the server
2. Do the dumpdata from your local in .json, then copy that json to your
server
3. Once on the server just load that json with the loaddata command.

On Mon, Nov 25, 2019 at 2:58 PM Ram  wrote:

> Hi Carlos,
>
> I see there is a typo in my previous steps which could have mislead you.
> Basically old and new sites are different databases. Old site is running
> remotely in local host on our Developer's machine with MySQL dB. Now I've
> setup new hosting server with Postgres database (empty site so far) in a
> Digital Ocean's droplet ( Ubuntu 18.04 OS).  So what I'm planning now is I
> will not run these commands in new server's virtual environment
>
> 4.1.(virtual env) ~/myprojectdir/manage.py makemigrations
> 4.2. (virtual env) ~/myprojectdir/manage.py migrate
> 4.3. (virtual env) ~/myprojectdir/manage.py collectstatic
>
> Before running the above, I will run all 'Migrating a Django app from
> MySQL to PostgreSQL' steps documented in your blog first and then proceed
> with the above commands in my server virtual environment.
>
> I believe I've to run your steps in virtual environment only right?
>
> Thanks,
> ~Ram
>
>
> On Mon, Nov 25, 2019 at 12:53 PM carlos  wrote:
>
>> i thing is good your plan copy your files local to server
>> then dumpdata in local database and copy to server and last you loaddata
>> in your server
>>
>> cheers
>>
>> On Sat, Nov 23, 2019 at 10:13 PM Mohammad yunus 
>> wrote:
>>
>>> Is this "migration" command will work for all type of databases or just
>>> only for sqllite3?
>>>
>>> On Sun, 24 Nov 2019, 9:12 am Ram,  wrote:
>>>
 Hi Carlos,

 If you get to see my email, could you review my plan and let me know
 whether my plan works for migration.

 1. I have setup new Ubuntu 18.04 server in Digital Ocean droplet
 2. Installed Postgress, Django with default settings and empty site,
 which means I did not bring/copy over the my Django project files yet
 3. My next step is to copy over all the Django project files which are
 located in my developer's localhost
 4. Once the files are copied to project folder in this new server I
 will have to run following commands, but I will not run these because old
 and new sites have same database software.
 4.1.(virtual env) ~/myprojectdir/manage.py makemigrations
 4.2. (virtual env) ~/myprojectdir/manage.py migrate
 4.3. (virtual env) ~/myprojectdir/manage.py collectstatic

 5. So I want to start with your steps pointed in your blog
 
 since I have to start with an empty Postgres database. I'm not sure whether
 this will work or not.
 6. Hopefully if all the commands are successful, I will run the above
 commands.

 Please let me know if my plan generally would work? I know you don't
 have complete picture, but I'm wondering if you have any thoughts about my
 use case?

 Thanks,
 ~Ram




 On Sat, Nov 23, 2019 at 4:32 PM Ram  wrote:

> Hello Carlos,
>
> The steps looks promising. We will try it and let you know.
>
> Our dB is originally from MySQL configured for PHP based website and
> later on we moved to Django project development. Now we planned to migrate
> the site to Postgres database running on Ubuntu for Django project.
>
> Thank you very much.,
> ~Ram
>
> On Sat, Nov 23, 2019 at 4:01 PM carlos  wrote:
>
>> maybe this link help you!
>> https://www.calazan.com/migrating-django-app-from-mysql-to-postgresql/
>>
>> On Sat, Nov 23, 2019 at 12:23 PM Ram  wrote:
>>
>>> Hi,
>>>
>>> We have our Django based website running in our local windows box
>>> with MySQL database. We plan to deploy our site on Ubuntu, Postgress,
>>> Gunicorn and Nginx stack server. I'm looking for a way to achieve this 
>>> even
>>> with the manual intervention? I appreciate if someone can point me the
>>> right direction with appropriate documentation.
>>>
>>> Thank,
>>> ~Ram
>>>
>>> --
>>> 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/CA%2BOi5F1mHwkiidgcUgFJDR0e9MGbJj%2BJTZWfKgVjXkS-uN9kEw%40mail.gmail.com
>>> 
>>> .
>>>
>>
>>
>> --
>> att.
>> Carlos Rocha
>>
>> --
>> You received this message because you are sub

Re: Trying to update a record using UpdateView Error: Circuitinfotable matching query does not exist

2019-11-25 Thread Patrick Carra
Sorry I forgot one! My models.py for this class is below:

class Circuitinfotable(models.Model):
   id1 = models.IntegerField(blank=True, null=True)
   pid = models.CharField(max_length=255, blank=True, null=True)
   circuitid = models.CharField(primary_key=True, max_length=255, blank=
False, null=False)
   bandwidth = models.CharField(max_length=255, blank=True, null=True)
   region = models.CharField(max_length=255, blank=True, null=True)
   bw = models.IntegerField(blank=True, null=True)
   tableaupathname = models.CharField(max_length=255, blank=True, null=True)
   handoffalocaddress = models.CharField(max_length=255, blank=True, null=
True)
   handoffaloccity = models.CharField(max_length=255, blank=True, null=True)
   handoffalocst = models.CharField(max_length=255, blank=True, null=True)
   alocationaddress = models.CharField(max_length=255, blank=True, null=True
)
   alocationcity = models.CharField(max_length=255, blank=True, null=True)
   alocst = models.CharField(max_length=255, blank=True, null=True)
   handoffzlocaddress = models.CharField(max_length=255, blank=True, null=
True)
   carrier = models.CharField(max_length=255, blank=True, null=True)
   handoffzloccity = models.CharField(max_length=255, blank=True, null=True)
   handoffzlocst = models.CharField(max_length=255, blank=True, null=True)
   zlocationaddress = models.CharField(max_length=255, blank=True, null=True
)
   zlocationcity = models.CharField(max_length=255, blank=True, null=True)
   zlocst = models.CharField(max_length=255, blank=True, null=True)
   segmentid = models.CharField(max_length=255, blank=True, null=True)
   segmenttype = models.CharField(max_length=255, blank=True, null=True)
   status = models.CharField(max_length=255, blank=True, null=True)
   purpose = models.CharField(max_length=255, blank=True, null=True)
   installdate = models.DateField(blank=True, null=True)
   termdate = models.DateField(blank=True, null=True)
   termlengthmos = models.IntegerField(blank=True, null=True)
   legacy = models.CharField(max_length=255, blank=True, null=True)
   installciopsticket = models.CharField(max_length=255, blank=True, null=
True)
   retermciopsticket = models.CharField(max_length=255, blank=True, null=
True)
   discociopsticket = models.CharField(max_length=255, blank=True, null=True
)
   notes = models.CharField(max_length=255, blank=True, null=True)
   kma = models.CharField(max_length=255, blank=True, null=True)
   group = models.IntegerField(blank=True, null=True)
   cktidkey = models.IntegerField(blank=True, null=True)
   visiolink = models.CharField(max_length=255, blank=True, null=True)
   latestjiraticket = models.CharField(max_length=255, blank=True, null=True
, unique=True)
   disconnectdate = models.DateField(blank=True, null=True)
   segmentname = models.CharField(max_length=255, blank=True, null=True)
   mrcnew = models.TextField(blank=True, null=True)  # This field type is a 
guess.
   termyrs = models.IntegerField(blank=True, null=True)
   monthbudget = models.IntegerField(blank=True, null=True)
   monthdisco = models.IntegerField(blank=True, null=True)
   mrcold = models.TextField(blank=True, null=True)  # This field type is a 
guess.
   kmz = models.CharField(max_length=255, blank=True, null=True)

class Meta:
   managed = False
   db_table = 'circuitinfotable'

def __str__(self):
   return self.circuitid

def get_absolute_url(self):
   return reverse('home')



-- 
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/b407aac9-aec7-4e45-b91a-9864c4be2d80%40googlegroups.com.


Trying to update a record using UpdateView Error: Circuitinfotable matching query does not exist

2019-11-25 Thread Patrick Carra
I have a built a database application that users can search and view 
records from.  I am trying to incorporate an update feature to allow users 
to edit information the app is called editLit.  When I try to pass a 
parameter into the editLit app via urls into views.py I get the following 
error:

Environment:


Request Method: GET
Request URL: http://*:8080/viewLit/edit/circuit/STTK-100G-18040-01-WRBB/

Django Version: 2.2.4
Python Version: 3.6.8
Installed Applications:
['editLit.apps.EditlitConfig',
 'viewLit.apps.ViewlitConfig',
 'searchLit.apps.SearchlitConfig',
 'homepage.apps.HomepageConfig',
 'base.apps.BaseConfig',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File 
"/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/django/core/handlers/exception.py"
 
in inner
  34. response = get_response(request)

File 
"/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/django/core/handlers/base.py"
 
in _get_response
  115. response = self.process_exception_by_middleware(e, 
request)

File 
"/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/django/core/handlers/base.py"
 
in _get_response
  113. response = wrapped_callback(request, *callback_args, 
**callback_kwargs)

File "/home/db_user/ciopsdb/viewLit/views.py" in viewLit
  14. record = Circuitinfotable.objects.get(circuitid=circuitid)

File 
"/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/django/db/models/manager.py"
 
in manager_method
  82. return getattr(self.get_queryset(), name)(*args, 
**kwargs)

File 
"/home/db_user/ciopsdb/venv/lib64/python3.6/site-packages/django/db/models/query.py"
 
in get
  408. self.model._meta.object_name

Exception Type: DoesNotExist at 
/viewLit/edit/circuit/STTK-100G-18040-01-WRBB/
Exception Value: Circuitinfotable matching query does not exist.

My template from which I start in a view app contains the a href link below:


Edit Circuit Info

my editLit.urls.py file contains:
from django.urls import path, include
from django.conf.urls import  url
from . import views

urlpatterns= [
 path('circuit//edit', 
views.editLit.as_view(),name='editLit'),
]


my editLit.views.py file contains:
from django.views.generic.edit import UpdateView

from . models import Circuitinfotable

# Create your views here.
class editLit(UpdateView):
model=Circuitinfotable
template="/editLit/editCircuit.html"
fields = '__all__'


And finally my template for the editLit class is:
{% block content %}


{% csrf_token %}
{{form.as_p}}





{% endblock %}


Any ideas about what I'm doing wrong are welcome I am still new to Django.  
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/985bf9e3-fbe4-4604-95db-9ee95ef10809%40googlegroups.com.


Session backend for production

2019-11-25 Thread Lorenzo Peña
Hello, fellow djangonauts!

Is there any particular reason why should I pick memcached backed sessions 
in production over db, or viceversa? Most documentation seems to slightly 
suggest that memcached should perform faster than database. Any other 
criteria I should be aware of? I am using single database for multi-tenant 
application, so I am expecting over-average db traffic.

Thanks in advance!
Lorenzo

-- 
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/ac9c9ede-86bf-4136-8bc1-91137e80e9ef%40googlegroups.com.


Django on an existing PostgreSQL Database?

2019-11-25 Thread Ulrich Goebel
Hi,

I have an existing PostgreSQL Database with about 20 tables, using 
collating sequences, foreign keys, triggers, and even additional indexes. 
For that database I want to write a WEB-frontend to insert, update and 
delete data in the database. I don't want to define the data model in 
python or django, but want to make django/python work on the existing 
database.

Is that possible? Where to find som helpful hints how to do that?

Best regards
Ulrich

-- 
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/a923c993-d03e-42cd-904f-3eabe811429b%40googlegroups.com.


Re: How to fix this - ERROR: Failed building wheel for mysqlclient

2019-11-25 Thread Ram
Hello Integr,

I did not understand your suggestion? How do I clear cache in Python
virtual environment? and what is other method you suggest based on the
install error that I'm hitting.

Best regards,
~Ram


On Mon, Nov 25, 2019 at 10:16 AM Integr@te System 
wrote:

> Hi man,
>
> Clear cache and try other method to requisite install.
>
> On Sun, Nov 24, 2019, 06:28 Ram  wrote:
>
>> Hello Kasper,
>>
>> I tried installing libssl1.1 globally and then tried mysqlclient install
>> in virtualenv, but the result is the same and mysqlclient is still failed
>> with same error.
>>
>> Thanks
>> ~Ram
>>
>> On Sat, Nov 23, 2019 at 3:59 PM Kasper Laudrup 
>> wrote:
>>
>>> Hi Ram,
>>>
>>> On 23/11/2019 23.48, Ram wrote:
>>> > Hi, I’m running into this blocking issue while setting up Django with
>>> > MySQL database. I’m pasting here what I tried so far on Ubuntu 18.04
>>> OS.
>>> >
>>> > |/(vkdev)user@ubuntu-he:~/testproject$ pip install mysqlclient
>>> > Collecting mysqlclient Using cached
>>> >
>>> https://files.pythonhosted.org/packages/d0/97/7326248ac8d5049968bf4ec708a5d3d4806e412a42e74160d7f266a3e03a/mysqlclient-1.4.6.tar.gz
>>> > Building wheels for collected packages: mysqlclient Building wheel
>>> > for mysqlclient (setup.py) ... error ERROR: Command errored out
>>> with
>>> > exit status 1: ... ... /usr/bin/ld: cannot find -lssl
>>> > /usr/bin/ld: cannot find -lcrypto collect2: error: ld returned 1
>>> > exit status error: command 'x86_64-linux-gnu-gcc' failed with exit
>>> > status 1  ERROR: Failed
>>> > building wheel for mysqlclient Running setup.py clean for
>>> > mysqlclient Failed to build mysqlclient Installing collected
>>> > packages: mysqlclient Running setup.py install for mysqlclient ...
>>> > error ERROR: Command errored out with exit status 1:/ |
>>> >
>>>
>>> You most likely need the package for openssl. Try installing the libssl
>>> package, ie. something like:
>>>
>>> # apt install libssl1.1
>>>
>>> Hopefully that should do it.
>>>
>>> Kind regards,
>>>
>>> Kasper Laudrup
>>>
>>> --
>>> 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/f67170f6-e3b7-294d-9e56-2abf9752edda%40stacktrace.dk
>>> .
>>>
>> --
>> 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/CA%2BOi5F0mmgO2jDRsDtXF6ZaVzku59QXFdrdRF%3DnwonnLb6CoMw%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAP5HUWon%2BVbxsTJwg1KrqrOqH6Hz%3D2DMSeTJpJZv%2BWwgeVYMiQ%40mail.gmail.com
> 
> .
>

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


Re: How to migrate Django site from MySQL database to Postgres?

2019-11-25 Thread Ram
Hi Carlos,

I see there is a typo in my previous steps which could have mislead you.
Basically old and new sites are different databases. Old site is running
remotely in local host on our Developer's machine with MySQL dB. Now I've
setup new hosting server with Postgres database (empty site so far) in a
Digital Ocean's droplet ( Ubuntu 18.04 OS).  So what I'm planning now is I
will not run these commands in new server's virtual environment

4.1.(virtual env) ~/myprojectdir/manage.py makemigrations
4.2. (virtual env) ~/myprojectdir/manage.py migrate
4.3. (virtual env) ~/myprojectdir/manage.py collectstatic

Before running the above, I will run all 'Migrating a Django app from MySQL
to PostgreSQL' steps documented in your blog first and then proceed with
the above commands in my server virtual environment.

I believe I've to run your steps in virtual environment only right?

Thanks,
~Ram


On Mon, Nov 25, 2019 at 12:53 PM carlos  wrote:

> i thing is good your plan copy your files local to server
> then dumpdata in local database and copy to server and last you loaddata
> in your server
>
> cheers
>
> On Sat, Nov 23, 2019 at 10:13 PM Mohammad yunus 
> wrote:
>
>> Is this "migration" command will work for all type of databases or just
>> only for sqllite3?
>>
>> On Sun, 24 Nov 2019, 9:12 am Ram,  wrote:
>>
>>> Hi Carlos,
>>>
>>> If you get to see my email, could you review my plan and let me know
>>> whether my plan works for migration.
>>>
>>> 1. I have setup new Ubuntu 18.04 server in Digital Ocean droplet
>>> 2. Installed Postgress, Django with default settings and empty site,
>>> which means I did not bring/copy over the my Django project files yet
>>> 3. My next step is to copy over all the Django project files which are
>>> located in my developer's localhost
>>> 4. Once the files are copied to project folder in this new server I will
>>> have to run following commands, but I will not run these because old and
>>> new sites have same database software.
>>> 4.1.(virtual env) ~/myprojectdir/manage.py makemigrations
>>> 4.2. (virtual env) ~/myprojectdir/manage.py migrate
>>> 4.3. (virtual env) ~/myprojectdir/manage.py collectstatic
>>>
>>> 5. So I want to start with your steps pointed in your blog
>>> 
>>> since I have to start with an empty Postgres database. I'm not sure whether
>>> this will work or not.
>>> 6. Hopefully if all the commands are successful, I will run the above
>>> commands.
>>>
>>> Please let me know if my plan generally would work? I know you don't
>>> have complete picture, but I'm wondering if you have any thoughts about my
>>> use case?
>>>
>>> Thanks,
>>> ~Ram
>>>
>>>
>>>
>>>
>>> On Sat, Nov 23, 2019 at 4:32 PM Ram  wrote:
>>>
 Hello Carlos,

 The steps looks promising. We will try it and let you know.

 Our dB is originally from MySQL configured for PHP based website and
 later on we moved to Django project development. Now we planned to migrate
 the site to Postgres database running on Ubuntu for Django project.

 Thank you very much.,
 ~Ram

 On Sat, Nov 23, 2019 at 4:01 PM carlos  wrote:

> maybe this link help you!
> https://www.calazan.com/migrating-django-app-from-mysql-to-postgresql/
>
> On Sat, Nov 23, 2019 at 12:23 PM Ram  wrote:
>
>> Hi,
>>
>> We have our Django based website running in our local windows box
>> with MySQL database. We plan to deploy our site on Ubuntu, Postgress,
>> Gunicorn and Nginx stack server. I'm looking for a way to achieve this 
>> even
>> with the manual intervention? I appreciate if someone can point me the
>> right direction with appropriate documentation.
>>
>> Thank,
>> ~Ram
>>
>> --
>> 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/CA%2BOi5F1mHwkiidgcUgFJDR0e9MGbJj%2BJTZWfKgVjXkS-uN9kEw%40mail.gmail.com
>> 
>> .
>>
>
>
> --
> att.
> Carlos Rocha
>
> --
> 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/CAM-7rO2Dm031aVT21qWyh_1nHSGUpzj3vYxZsXaN_Y1nTGppOw%40mail.gmail.com
> 

Re: How to migrate Django site from MySQL database to Postgres?

2019-11-25 Thread carlos
i thing is good your plan copy your files local to server
then dumpdata in local database and copy to server and last you loaddata in
your server

cheers

On Sat, Nov 23, 2019 at 10:13 PM Mohammad yunus  wrote:

> Is this "migration" command will work for all type of databases or just
> only for sqllite3?
>
> On Sun, 24 Nov 2019, 9:12 am Ram,  wrote:
>
>> Hi Carlos,
>>
>> If you get to see my email, could you review my plan and let me know
>> whether my plan works for migration.
>>
>> 1. I have setup new Ubuntu 18.04 server in Digital Ocean droplet
>> 2. Installed Postgress, Django with default settings and empty site,
>> which means I did not bring/copy over the my Django project files yet
>> 3. My next step is to copy over all the Django project files which are
>> located in my developer's localhost
>> 4. Once the files are copied to project folder in this new server I will
>> have to run following commands, but I will not run these because old and
>> new sites have same database software.
>> 4.1.(virtual env) ~/myprojectdir/manage.py makemigrations
>> 4.2. (virtual env) ~/myprojectdir/manage.py migrate
>> 4.3. (virtual env) ~/myprojectdir/manage.py collectstatic
>>
>> 5. So I want to start with your steps pointed in your blog
>> 
>> since I have to start with an empty Postgres database. I'm not sure whether
>> this will work or not.
>> 6. Hopefully if all the commands are successful, I will run the above
>> commands.
>>
>> Please let me know if my plan generally would work? I know you don't have
>> complete picture, but I'm wondering if you have any thoughts about my use
>> case?
>>
>> Thanks,
>> ~Ram
>>
>>
>>
>>
>> On Sat, Nov 23, 2019 at 4:32 PM Ram  wrote:
>>
>>> Hello Carlos,
>>>
>>> The steps looks promising. We will try it and let you know.
>>>
>>> Our dB is originally from MySQL configured for PHP based website and
>>> later on we moved to Django project development. Now we planned to migrate
>>> the site to Postgres database running on Ubuntu for Django project.
>>>
>>> Thank you very much.,
>>> ~Ram
>>>
>>> On Sat, Nov 23, 2019 at 4:01 PM carlos  wrote:
>>>
 maybe this link help you!
 https://www.calazan.com/migrating-django-app-from-mysql-to-postgresql/

 On Sat, Nov 23, 2019 at 12:23 PM Ram  wrote:

> Hi,
>
> We have our Django based website running in our local windows box with
> MySQL database. We plan to deploy our site on Ubuntu, Postgress, Gunicorn
> and Nginx stack server. I'm looking for a way to achieve this even with 
> the
> manual intervention? I appreciate if someone can point me the right
> direction with appropriate documentation.
>
> Thank,
> ~Ram
>
> --
> 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/CA%2BOi5F1mHwkiidgcUgFJDR0e9MGbJj%2BJTZWfKgVjXkS-uN9kEw%40mail.gmail.com
> 
> .
>


 --
 att.
 Carlos Rocha

 --
 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/CAM-7rO2Dm031aVT21qWyh_1nHSGUpzj3vYxZsXaN_Y1nTGppOw%40mail.gmail.com
 
 .

>>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CA%2BOi5F1F3_sSVXm1igaP%3DTAKv-2kf0Ux6bXWvCKaQs0HZr_Yvg%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAEQiGcM8cW%3DOjkKjk2quBThXUGQNQDkKvFumn_%2BxvQBJPJnnsg%40mail.gmail.com
> 

self.foreign_related_fields[0] IndexError: tuple index out of range

2019-11-25 Thread Ahmad Saki
My custom authentication model in django:

from django.db import models
from django.contrib.auth.models import (
AbstractBaseUser, BaseUserManager
)
from organization.models import Organization


class UserManager(BaseUserManager):
# use_in_migrations = True

# python manage.py createsuperuser
def create_user(self, orgid, username, email,  password=None, is_admin=False, 
is_staff=False, is_active=True):
if not orgid:
raise ValueError("Organization of user must not empty")
elif not username:
raise ValueError("User must have an username")
elif not email:
raise ValueError("User must have an email address")

org_obj = Organization.objects.all(orgid=orgid)
user_obj = self.model(
orgid=org_obj,
username=username,
email = self.normalize_email(email),
password=password
)
user_obj.set_password(password)
user_obj.admin=is_admin
user_obj.staff=is_staff
user_obj.active=is_active
user_obj.save(using=self._db)
return user_obj

# python manage.py createsuperuser
def create_superuser(self, orgid, username, email, password=None):
user = 
self.create_user(orgid,username,email,password=password,is_admin=True,is_staff=True,is_active=True)
return user

def create_staffuser(self, orgid, username, email, password=None):
user = 
self.create_user(orgid,username,email,password=password,is_admin=False,is_staff=True,is_active=True)
return user

class User(AbstractBaseUser):
orgid   = models.ForeignKey(Organization, max_length=6, 
on_delete=models.CASCADE)
username= models.CharField(primary_key=True, max_length=50) 
email   = models.EmailField(max_length=255, unique=True, null=False, 
blank=False)
admin   = models.BooleanField(default=False)
staff   = models.BooleanField(default=False)
active  = models.BooleanField(default=True)
date_joined = models.DateTimeField(auto_now_add=True)

objects = UserManager()

USERNAME_FIELD = "username"
# REQUIRED_FIELDS must contain all required fields on your User model, 
# but should not contain the USERNAME_FIELD or password as these fields will 
always be prompted for.
REQUIRED_FIELDS = ['orgid','email']

class Meta:
app_label = "user"
db_table = "user"

def __str__(self):
return self.username

def get_full_name(self):
return self.username

def get_short_name(self):
return self.username

# this methods are require to login super user from admin panel
def has_perm(self, perm, obj=None):
return self.is_staff

# this methods are require to login super user from admin panel
def has_module_perms(self, app_label):
return self.is_staff

@property
def is_admin(self):
return self.admin

@property
def is_staff(self):
return self.staff

@property
def is_active(self):
return self.active



When I create migrations it creates:

from django.db import migrations, models
import django.db.models.deletion
import user.models


class Migration(migrations.Migration):

initial = True

dependencies = [
('organization', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='User',
fields=[
('password', models.CharField(max_length=128, 
verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, 
verbose_name='last login')),
('username', models.CharField(max_length=50, primary_key=True, 
serialize=False)),
('email', models.EmailField(max_length=255, unique=True)),
('admin', models.BooleanField(default=False)),
('staff', models.BooleanField(default=False)),
('active', models.BooleanField(default=True)),
('date_joined', models.DateTimeField(auto_now_add=True)),
('orgid', models.ForeignKey(max_length=6, 
on_delete=django.db.models.deletion.CASCADE, to='organization.Organization')),
],
options={
'db_table': 'user',
},
managers=[
('objects', user.models.UserManager()),
],
),
]



But when I want to migrate it gives me an error below. Please help me 
anyone..

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, organization, sessions, user
Running migrations:
  Applying admin.0004_auto_20191118_2315...Traceback (most recent call last):
  File "manage.py", line 21, in 
main()
  File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
  File 
"C:\Users\ZAB-SAKI\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py",
 line 381, in execute_from_command_line
utility.execute()
  File 
"C:\Users\ZAB-SAKI\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py",
 line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"C:\Users\ZAB-SAKI\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\base.py",
 line 323, in run_from_argv
sel

Re: How to fix this - ERROR: Failed building wheel for mysqlclient

2019-11-25 Thread Integr@te System
Hi man,

Clear cache and try other method to requisite install.

On Sun, Nov 24, 2019, 06:28 Ram  wrote:

> Hello Kasper,
>
> I tried installing libssl1.1 globally and then tried mysqlclient install
> in virtualenv, but the result is the same and mysqlclient is still failed
> with same error.
>
> Thanks
> ~Ram
>
> On Sat, Nov 23, 2019 at 3:59 PM Kasper Laudrup 
> wrote:
>
>> Hi Ram,
>>
>> On 23/11/2019 23.48, Ram wrote:
>> > Hi, I’m running into this blocking issue while setting up Django with
>> > MySQL database. I’m pasting here what I tried so far on Ubuntu 18.04 OS.
>> >
>> > |/(vkdev)user@ubuntu-he:~/testproject$ pip install mysqlclient
>> > Collecting mysqlclient Using cached
>> >
>> https://files.pythonhosted.org/packages/d0/97/7326248ac8d5049968bf4ec708a5d3d4806e412a42e74160d7f266a3e03a/mysqlclient-1.4.6.tar.gz
>> > Building wheels for collected packages: mysqlclient Building wheel
>> > for mysqlclient (setup.py) ... error ERROR: Command errored out with
>> > exit status 1: ... ... /usr/bin/ld: cannot find -lssl
>> > /usr/bin/ld: cannot find -lcrypto collect2: error: ld returned 1
>> > exit status error: command 'x86_64-linux-gnu-gcc' failed with exit
>> > status 1  ERROR: Failed
>> > building wheel for mysqlclient Running setup.py clean for
>> > mysqlclient Failed to build mysqlclient Installing collected
>> > packages: mysqlclient Running setup.py install for mysqlclient ...
>> > error ERROR: Command errored out with exit status 1:/ |
>> >
>>
>> You most likely need the package for openssl. Try installing the libssl
>> package, ie. something like:
>>
>> # apt install libssl1.1
>>
>> Hopefully that should do it.
>>
>> Kind regards,
>>
>> Kasper Laudrup
>>
>> --
>> 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/f67170f6-e3b7-294d-9e56-2abf9752edda%40stacktrace.dk
>> .
>>
> --
> 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/CA%2BOi5F0mmgO2jDRsDtXF6ZaVzku59QXFdrdRF%3DnwonnLb6CoMw%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAP5HUWon%2BVbxsTJwg1KrqrOqH6Hz%3D2DMSeTJpJZv%2BWwgeVYMiQ%40mail.gmail.com.


Re: Django- Display PDf document in an Iframe or Pdf VIewer

2019-11-25 Thread Mark Phillips
Lucas,

I have many documents that I have uploaded to my django app. The docs are
stored in the file system, but the path is in my django model. The docs are
either pdfs or png images.

This is how I am displaying pdf images in my ModelAdmin change form:

  readonly_fields = ('get_image_3', )

def get_image_3(self, obj):
display_image = ""
if (obj.document_id):
# Get the path to the main image
doc_file_path = obj.document_id.storage_file_name.path
if obj.document_id.storage_file_name.name.endswith('pdf'):
display_image = 'http://www.adobe.com/products/acrobat/readstep2.html";>'.format(image_link =
obj.document_id.storage_file_name.url)
else:
display_image = 'Click to tag people, Ctrl-click to
tag animals'.format(document_link =
obj.document_id.storage_file_name.url, doc_id=obj.document_id.document_id,
height=settings.FACE_ADMIN_PREVIEW_HEIGHT)
return format_html(display_image)

The adobe reader renders a nice window for scrolling the pdf and changing
pages.

To display a thumbnail of the pdf on the main ModelAdmin page, I used
Pillow to grab the first page of the pdf and make a jpg thumbnail of that
page. Then use similar code from the display_image above after the else
(for displaying an image on the page in the admin).

Hope that helps!

Mark

On Mon, Nov 25, 2019 at 7:46 AM 'Lucas Gärtner' via Django users <
django-users@googlegroups.com> wrote:

> Hello everyone!
>
> I just signed up here, so maybe this thread is wrong in this group.
>
> The problem is as follows:
>
> I need to display a PDF document in a half of a web application.
> I tried it first with Iframe and now today with pdf.js.
> Nothing helped. Do you have any idea?
> It is only showing the pdf, not more.
>
> I am using django: 2.1.10 and Python 3.7.1
>
> Hope you have some good recommendations!
>
> Have a nice day!
> Lucas
>
> --
> 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/8304b914-3861-4c33-8948-87f9baeaf27f%40googlegroups.com
> 
> .
>

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


When to use Admin model_delete/model_save and Model delete/save?

2019-11-25 Thread Mark Phillips
Just curious as to the best practices for using save/delete in Model versus
delete_model/save_model in ModelAdmin. Is one preferred over the other?

In my particular case, I have a Document model with a JSON field that holds
a bunch of metadata (name:value pairs) for Documents (photos, pdfs, etc).
The metadata is defined in other models (MetaData for names and
MetaDataValue for the value(s)), so I can change the metadata names and
values at run time.

When an existing MetaData name or value changes or is deleted, I need to
"scrub" the metadata stored in the Document model to change/delete the
metadata names/values to keep them in sync with what is defined in the
MetaData and MetaDataValue models. All these changes are done through the
Admin screens.

Would it be more appropriate to use model_save and model_delete in the
Admin or save and delete in the respective models? Functionally, it does
not matter as far as I can see. I am just wondering if there is a preferred
way, or a more "django idiomatic" way to do this.

Thanks!
Mark

-- 
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/CAEqej2PGgK%3D%2BEyqrTj3Ds9s8YAOjuW0bB5wYPqedxRFsp9e6zA%40mail.gmail.com.


Django- Display PDf document in an Iframe or Pdf VIewer

2019-11-25 Thread 'Lucas Gärtner' via Django users
Hello everyone!

I just signed up here, so maybe this thread is wrong in this group. 

The problem is as follows:

I need to display a PDF document in a half of a web application.
I tried it first with Iframe and now today with pdf.js.
Nothing helped. Do you have any idea? 
It is only showing the pdf, not more.

I am using django: 2.1.10 and Python 3.7.1

Hope you have some good recommendations!

Have a nice day!
Lucas

-- 
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/8304b914-3861-4c33-8948-87f9baeaf27f%40googlegroups.com.


Re: Internal error 500

2019-11-25 Thread Integr@te System
Hi friend,

Inspect backward to previous error how you customized and see change in log
system of backend srv.
U can attemp to run localhost first.

On Mon, Nov 25, 2019, 20:29 Josiah Umezurike <
pcintegral.pcintegr...@gmail.com> wrote:

> I was able to fix those now I have this error.
>
>
> On Saturday, November 23, 2019 at 2:14:31 PM UTC-5, Josiah Umezurike wrote:
>>
>> I was configuring django few days ago it seems that all went well. Then I
>> started getting internal error 500.
>>
>> my domain is apilokdon.com or www.apilokdon.com
>>
>> I am not sure what is happening: I check nginx_config, wsgi_params and
>> /etc/hosts
>>
>> I can't see any error on configuration but when I run.
>>
>> python manage.py runserver
>>
>>
>> python manage.py check
>>
>>
>>
>> check if nginx runs:
>>
>>
>> My gitlab site works. So I am not sure if it nginx or uwsgi
>>
>> I went into the virtual env and ran.
>> uwsgi --ini [app name].ini
>>
>> I checked my site nothing is working now: No more internal server error
>> but site is not displaying.
>>
>>
>>
>>
>>
>> I have done all I could on this but my site cannot display but port 
>> which is gitlab.apilokdon.comAny help or direction to the positive side
>> will be great. Thanks.
>>
>>
>>
>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e15983ac-7fa3-484a-8d4d-dd75a65f839f%40googlegroups.com
> 
> .
>

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


Re: Internal error 500

2019-11-25 Thread Josiah Umezurike
I was able to fix those now I have this error.


On Saturday, November 23, 2019 at 2:14:31 PM UTC-5, Josiah Umezurike wrote:
>
> I was configuring django few days ago it seems that all went well. Then I 
> started getting internal error 500.
>
> my domain is apilokdon.com or www.apilokdon.com
>
> I am not sure what is happening: I check nginx_config, wsgi_params and 
> /etc/hosts
>
> I can't see any error on configuration but when I run.
>
> python manage.py runserver
>
>
> python manage.py check
>
>
>
> check if nginx runs:
>
>
> My gitlab site works. So I am not sure if it nginx or uwsgi
>
> I went into the virtual env and ran.
> uwsgi --ini [app name].ini
>
> I checked my site nothing is working now: No more internal server error 
> but site is not displaying.
>
>
>
>
>
> I have done all I could on this but my site cannot display but port  
> which is gitlab.apilokdon.comAny help or direction to the positive side 
> will be great. Thanks.
>
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e15983ac-7fa3-484a-8d4d-dd75a65f839f%40googlegroups.com.


Customer specific translations

2019-11-25 Thread Jani Tiainen
I've use-case where my django app is delivered to multiple customers in
multiple languages.

Due the nature of application end users do use for certain terms their own
wording, which differ significantly from others.

For example:

"Delivery route". Some may call it "driving route". Some "route" and some
just "delivery route".

Any ideas how to handle this?

-- 
Jani Tiainen
Software wizard

https://blog.jani.tiainen.cc/

Always open for short term jobs or contracts to work with Django.

-- 
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/CAHn91odVXDb_Tu3pAmmKtZMNZZyLDzHak9WMmMxU6HZrY0v_Zg%40mail.gmail.com.


Re: Generic view template seems to have empty input

2019-11-25 Thread 山村維宏
Maybe you should use ListView, not DetailView.

2019年11月25日(月) 19:44 Manos Zeakis :

> Hi
>
> I have declared a model and the simple views I created are working.
>
> Now I am trying to move to generic views.
>
> So I added in urls.py
>
> path('book2//', views.DetailView.as_view(), name='detail'),
>
> And in views.py
>
> class DetailView(generic.DetailView):
> model = Book
>
> And the template is
>
> {% block content %}
>
>   book List
>   {% if object_list %}
>   
> {% for book in object_list %}
>   
> {{ book.author }}
>   
> {% endfor %}
>   
>   {% else %}
> There are no books in the library.
>   {% endif %}
>
> {% endblock %}
>
> For reference the models.py had been
>
> class Book(models.Model):
> author = models.CharField(max_length=70)
>
> But the result is "There are no books in the library". So it seems that
> the books list is not transferred to the template to be rendered. Could you
> help me understand where I have done wrong?
>
> Thank you
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/0c7de55c-4923-447a-9bf0-0ea962ca3542%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADM-sYV7aFMG%3DPF_swHvc341TaKjK9W_i3ebD8t%2BnEyxBTkqgw%40mail.gmail.com.


Re: Generic view template seems to have empty input

2019-11-25 Thread 山村維宏
Sorry, I mistaked.
You can use Detail view.

DetailView pass your model data, which named "book"(because model name is
Book).
Model doesn't list.

2019年11月25日(月) 19:44 Manos Zeakis :

> Hi
>
> I have declared a model and the simple views I created are working.
>
> Now I am trying to move to generic views.
>
> So I added in urls.py
>
> path('book2//', views.DetailView.as_view(), name='detail'),
>
> And in views.py
>
> class DetailView(generic.DetailView):
> model = Book
>
> And the template is
>
> {% block content %}
>
>   book List
>   {% if object_list %}
>   
> {% for book in object_list %}
>   
> {{ book.author }}
>   
> {% endfor %}
>   
>   {% else %}
> There are no books in the library.
>   {% endif %}
>
> {% endblock %}
>
> For reference the models.py had been
>
> class Book(models.Model):
> author = models.CharField(max_length=70)
>
> But the result is "There are no books in the library". So it seems that
> the books list is not transferred to the template to be rendered. Could you
> help me understand where I have done wrong?
>
> Thank you
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/0c7de55c-4923-447a-9bf0-0ea962ca3542%40googlegroups.com
> 
> .
>

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


Generic view template seems to have empty input

2019-11-25 Thread Manos Zeakis
Hi 

I have declared a model and the simple views I created are working.

Now I am trying to move to generic views. 

So I added in urls.py

path('book2//', views.DetailView.as_view(), name='detail'),

And in views.py

class DetailView(generic.DetailView):
model = Book

And the template is

{% block content %}

  book List
  {% if object_list %}
  
{% for book in object_list %}
  
{{ book.author }}
  
{% endfor %}
  
  {% else %}
There are no books in the library.
  {% endif %}   

{% endblock %}

For reference the models.py had been

class Book(models.Model):
author = models.CharField(max_length=70)

But the result is "There are no books in the library". So it seems that the 
books list is not transferred to the template to be rendered. Could you 
help me understand where I have done wrong?

Thank you

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0c7de55c-4923-447a-9bf0-0ea962ca3542%40googlegroups.com.


Re: Best way to organize custom admin views?

2019-11-25 Thread Wim Olivier
Hi,

I'd recommend using seperate apps for custom admin areas (1 app for each), 
and implementing a middleware that allows access to the relevant admin 
based on roles/permissions, etc.
It's simple, kept seperate from other code/apps nicely, and easy to limit 
access to different groups.

blogapp/
blogappadmin/
hrapp/
hrappadmin/


Regards,
Wim

On Friday, 22 November 2019 21:04:41 UTC+2, Jay wrote:
>
> What's the best way (or the standard way, or your preferred way) to 
> organize custom admin views? Assuming we want to leave the built-in Django 
> Admin in place and create entirely new admin views, would the optimal 
> organization be:
>
> *A new app?*
> blogapp/
>   views.py
>   viewsets.py
>   models.py
> shoppingapp/
>   views.py
>   viewsets.py
>   models.py
> adminapp/
>   views.py
>   viewsets.py
>   models.py
>
>
> *Directories within each app?*
> blogapp/
>   admin/
> views.py
> viewsets.py
> models.py
> shoppingapp/
>   admin/
> views.py
> viewsets.py
> models.py
>
>
> *A flat structure?*
> blogapp/
>   admin_views.py
>   admin_viewsets.py
>   admin_models.py
>   views.py
>   viewsets.py
>   models.py
> shoppingapp/
>   admin_views.py
>   admin_viewsets.py
>   admin_models.py
>   views.py
>   viewsets.py
>   models.py
>
>
> *Something else altogether?*
>
>
>> *It’s usually not worth it to heavily customize the Django admin. 
>> Sometimes, creating a simple view or form from scratch results in the same 
>> desired functionality with a lot less work. We’ve always had better results 
>> with creating custom management dashboards for client projects than we have 
>> with modifying the admin to fit the need of the client.”Excerpt From: 
>> Daniel Roy Greenfeld. “Two Scoops of Django 1.11.”*
>
>
>
>

-- 
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/dd8b11c1-2344-4915-93b2-808a07a838db%40googlegroups.com.