Re: Django rest framework Version

2018-01-08 Thread Xavier Ordoquy
Hi,

Out of curiosity, is there anything wrong with the latest version ?

Regards,
Xavier.

> Le 9 janv. 2018 à 04:59, Rakhee Menon  a écrit :
> 
> Hey!!!
> Please can anyone tell whats the stable version of django rest framework to 
> be used for production.
> Thanks in Advance.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com 
> .
> To post to this group, send email to django-users@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/1d4378ba-c467-4712-b4c6-fdd8003e9a83%40googlegroups.com
>  
> .
> For more options, visit https://groups.google.com/d/optout 
> .

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


Re: Upload file to a dynamically generated location

2018-01-08 Thread Andréas Kühne
Hi,

If you look at the documentation for the upload_to parameter, you can see
that you can do exactly what you want:
https://docs.djangoproject.com/en/2.0/ref/models/fields/#django.db.models.FileField.upload_to

The upload_to method (in your case "get_user_document_directory") can take
2 parameters:
ArgumentDescription
instance

An instance of the model where the FileField is defined. More specifically,
this is the particular instance where the current file is being attached.

In most cases, this object will not have been saved to the database yet, so
if it uses the default AutoField, *it might not yet have a value for its
primary key field*.
filename The filename that was originally given to the file. This may or
may not be taken into account when determining the final destination path.

So you don't need to add "self", you get that automatically. All you need
to do is change the method to:

def get_user_document_directory(instance, filename):
return "media/{0}/{1}/documents/{2}".format(instance.bundle.user,
instance.bundle.name, filename)

You have to remember to include the filename as well (it's not only the
directory but the entire path).

Regards,

Andréas

2018-01-08 21:34 GMT+01:00 :

> Hey Friends,
>
> I'm having trouble figuring out how to upload a document model to a
> dynamically generated location.  The following models.py file contains two
> models and a helper function
>
>
> views.py
>
>
> # I would like the string inputs to be self.bundle.user, and
> self.bundle.name  where self is the document model.  I know this doesn't
> work which is why I am here asking this question.
> def get_user_document_directory():
> document_directory = 'media/{0}/{1}/documents/'.format( , _ )
> return document_directory
>
> class Bundle(models.Model):
> user = models.ForeignKey(User)
> name = models.CharField(max_length=100)
>
> class Document(models.Model):
> bundle = models.ForeignKey(Bundle)
> name = models.CharField(max_length=100)
> description = models.CharField(max_length=100)
> document = models.FileField(upload_to=get_user_document_directory(self
> ) ) # I know passing self doesn't work but just trying to get the point
> across of what I am trying to do.
> uploaded_at = models.DateTimeField(auto_now_add=True)
>
>
>
> Any comments about how to remedy this situation would be greatly
> appreciated.
>
> Thanks,
> K
>
> --
> 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/71125202-9b89-4572-a086-ab9fed2b4d01%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: How do I make a Django model from a tab-delimited data file?

2018-01-08 Thread Andréas Kühne
Hi,

You will have to parse the CSV file manually with a custom management
command (at least that is what I would do). All you need to do is open the
file, split each row with a "," and then  import the correct columns to the
model.

You can also use something like pandas to convert the CSV file into
something that you can create the models from. But that may be overkill in
your case.

Regards,

Andréas

2018-01-09 3:38 GMT+01:00 Tom Tanner :

> I have a tab-delimited data file that looks something like this:
>
>
> NAME S1903_C02_001E state county tract State-County-Tract-ID
> Census Tract 201, Autauga County, Alabama 66000 01 001 020100 01001020100
> Census Tract 202, Autauga County, Alabama 41107 01 001 020200 01001020200
> Census Tract 203, Autauga County, Alabama 51250 01 001 020300 01001020300
>
> I want to make a Django model named `MyModel` with three columns: "name",
> "data", and "geoid", which correspond to the file's columns "NAME",
> "S1903_C02_001E", and "State-County-Tract-ID." Can I do this via command
> line, or with a custom Python script? I'm running my Django project locally
> on a computer running Debian 9.3.
>
> --
> 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/389d8f38-6dbc-43a0-8a69-d20aa13ca844%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Django rest framework Version

2018-01-08 Thread Andréas Kühne
Hi,

Just get the latest version of DRF (currently 3.7.7) - as long as the
version of django you are running is supported by the DRF version.

Regards,

Andréas

2018-01-09 4:59 GMT+01:00 Rakhee Menon :

> Hey!!!
> Please can anyone tell whats the stable version of django rest framework
> to be used for production.
> Thanks in Advance.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/1d4378ba-c467-4712-b4c6-fdd8003e9a83%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Managing a process from Django

2018-01-08 Thread Antonis Christofides
Ah, OK, sorry I didn't read all the discussion. So I guess that if you keep that
in a global variable, it won't work if your Django app is running in many
processes. (Besides, global variables are rarely a good idea.)

If I understand the problem correctly, what I would do would probably be to
touch a file whenever I make a change and examine the file modification date
each time—if it's more recent than last time I checked, the data has been 
modified.

Another option is to use the cache. For example, use memcached and store some
data in there. IIRC the cache is shared among all instances of Django.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2018-01-09 00:00, Kasper Laudrup wrote:
> Hi Antonis,
>
> On 2018-01-08 22:46, Antonis Christofides wrote:
>> OK, but why do you need this? What functionality is this going to have?
>>
>
> As I wrote in my original question, I'm attempting to write a Django
> application for managing DHCP leases and DNS entries.
>
> So, if a user changes an entry by modifying a model in Django, I need to
> update some external files and restart a process so the new files will be 
> reread.
>
> I might be approaching this the wrong way, but I would really like my Django
> application to "own" this process, so I would like a global instance of that
> which I could start/restart/kill from my Django application.
>
> I'm perfectly open for other ways to solve this, it just seemed like a fairly
> obvious way to do it, but I could very well be wrong.
>
> Thanks a lot and 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 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/a504b4ac-1ee8-b39d-21a5-dc9042fef25e%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: urlopen error [Errno 110] Connection timed out

2018-01-08 Thread suase9303
yes, i use a urlopen to crawl the some site. 
like this:
   html = urlopen(page)
   bs0bj = BeautifulSoup(html, "html.parser")

and error happen  in " /usr/lib/python3.5/urllib/request.py in do_open, "

when i open 'the site', the loading time is longer than others. then others 
which i crawl dont happen error 110.
so i think the site loading time is the source of error. maybe the loading 
time exceed the timeout deadline.

i want to length the timeout deadline, like timeout = None...


2018년 1월 9일 화요일 오전 1시 49분 56초 UTC+9, suas...@gmail.com 님의 말:
>
>
> I use pythonanywhere. At this time, "urlopen error [Errno 110] Connection 
> timed out" occurs. So I set CACHES TIMEOUT to None in Django settings.py. 
> However, error 110 still occurs. Do I need to change the timeout value in 
> urllib / request.py? I would really appreciate your help in this matter.
>

-- 
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/7838022c-886f-4cf9-8da7-5dc44c41551f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django rest framework foreign key display details from table 1 to table 2

2018-01-08 Thread cherngyorng
I have 2 model, MyUser, Family.

What i want to do is display users details in Family table based on the 
MyUser table. It is like adding friends or family in other social media and 
display them

In my current Family table, there are these 3 field. userId , familyId and 
relationship

userId(foreign key from MyUser table) = current user
familyId(foreign key from MyUser table) = current user's family member
relationship = who is the family member to the current user (eg: mother, 
father)

But i want to display **only some of** userId and familyId details from 
MyUser so the result will be like this:

**expected result**

userId = { id = 1, username = tom, image = 
"/media/images1/asdasdsda000.PNG"}
familyId = { id = 2, username = steve, image = 
"/media/images1/asdasdsda111.PNG"}
relationship = father
 
**current result**

userId = 1
familyId = 2
relationship = father

How do i do it ? I thought about nested serializer but i only want to 
display user details but not edit it from there. 

Here is my code:

**models.py**

class MyUser(AbstractUser):
userId = models.AutoField(primary_key=True)
image1 = models.ImageField(upload_to='images1')
dob = models.DateField(blank=True, null=True)
gender = models.CharField(max_length=6)

class Family(models.Model):
userId = models.ForeignKey(MyUser)
familyId = models.ForeignKey(MyUser)
relationship = models.CharField(max_length = 20)

**serializer.py**

class MyUserSerializer(serializers.ModelSerializer):
class Meta:
model = MyUser
fields = ['userId', 'username', 'email', 'first_name', 
'last_name', 'image']
read_only_fields = ('userId',)
extra_kwargs = {"password": {"write_only": True}}

class FamilySerializer(serializers.ModelSerializer):
class Meta:
model = Family
fields = ('id', 'userId', 'familyId', 'relationship')

**views.py**

class MyUserViewSet(viewsets.ModelViewSet):
permission_classes = [AllowAny]
queryset = MyUser.objects.all()
serializer_class = MyUserSerializer

class MyUserViewSet(viewsets.ModelViewSet):
permission_classes = [AllowAny]
queryset = Family.objects.all()
serializer_class = FamilySerializer

-- 
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/59b03f60-c230-4fb3-817b-600883fda73f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django rest framework Version

2018-01-08 Thread Rakhee Menon
Hey!!!
Please can anyone tell whats the stable version of django rest framework to 
be used for production.
Thanks in Advance.

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


How do I make a Django model from a tab-delimited data file?

2018-01-08 Thread Tom Tanner
I have a tab-delimited data file that looks something like this:


NAME S1903_C02_001E state county tract State-County-Tract-ID
Census Tract 201, Autauga County, Alabama 66000 01 001 020100 01001020100
Census Tract 202, Autauga County, Alabama 41107 01 001 020200 01001020200
Census Tract 203, Autauga County, Alabama 51250 01 001 020300 01001020300

I want to make a Django model named `MyModel` with three columns: "name", 
"data", and "geoid", which correspond to the file's columns "NAME", 
"S1903_C02_001E", and "State-County-Tract-ID." Can I do this via command 
line, or with a custom Python script? I'm running my Django project locally 
on a computer running Debian 9.3. 

-- 
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/389d8f38-6dbc-43a0-8a69-d20aa13ca844%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Simple file uploading app

2018-01-08 Thread Mike Morris
Though it is not a Drupal app, there is an excellent drop box type app 
in PHP called "Download Ticket Service"... simple, no frills, entirely 
cross-platform and open:


http://www.thregr.org/~wavexx/software/dl/

I have no idea if it could be readily incorporated into your app, but 
just FYI


From their website:


“dl” is a simple file sharing service for quick/one-off file 
transfers. Upload a file to get a link you can share. Or create a 
sharing link to receive files from others. The uploaded files are 
automatically removed when left unused, requiring zero 
additional maintenance.


“dl” is/built for your users/: easy to use with any browser, 
integrates smoothly withThunderbird 
for 
large attachments, works onAndroid 
,Windows,OSX 
or straight 
from thecommand line 
for 
maximum convenience.








On 01/08/2018 04:16 AM, guettli wrote:
Just for the records: Since I found no matching solution I wrote a 
generic http upload tool: https://pypi.python.org/pypi/tbzuploader/


For ftp there are thousands of clients, for automated upload via http 
I found none. That's why I wrote above tool.


Regards,
  Thomas

Am Mittwoch, 25. Oktober 2017 16:57:31 UTC+2 schrieb guettli:

I need a simple file uploading app.

Every user should be able to upload files to his own area.

This is the basic feature. You could think of additional goodies,
but the first step is
above feature.

I tried to find an application which implements this, but failed.

I tried this and other searches:

https://djangopackages.org/search/?q=upload



Before I start coding, I wanted to ask here, because I prefer
re-using to re-inventing :-)

Do you know an app which gives me this feature?

Regards,
  Thomas Güttler


--
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/016f37e6-3d91-40bc-bef5-8da625125117%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


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


Re: How do I use Django to execute PostGIS query to get polygons within four points?

2018-01-08 Thread Tom Tanner
Nah, didn't seem to work either. I ended up going with 
`.execute()`: 
https://docs.djangoproject.com/en/2.0/topics/db/sql/#executing-custom-sql-directly

On Sunday, January 7, 2018 at 11:49:16 PM UTC-5, Jani Tiainen wrote:
>
> Hi.
>
> __within is probably correct lookup. 
>
> You can find all lookups at:  
> https://docs.djangoproject.com/en/2.0/ref/contrib/gis/geoquerysets/
>
> 8.1.2018 2.36 "Tom Tanner" > 
> kirjoitti:
>
>> I get this error when trying Jani's example: "FieldError: Unsupported 
>> lookup 'inside' for MultiPolygonField or join on the field not permitted."
>>
>> On Sunday, January 7, 2018 at 7:33:51 PM UTC-5, Tom Tanner wrote:
>>>
>>> Thanks for replying, Jani. I should mention My `geom` field is a 
>>> MultiPolygon, so I can't use `from_bbox` it seems...
>>>
>>> On Sunday, January 7, 2018 at 3:45:55 AM UTC-5, Jani Tiainen wrote:

 Something like following should work. Didn't checked if that actually 
 works.

 Mymodel.objects.filter(geom__inside=Polygon.from_bbox((x1,y1,x2,y2), 
 srid=1234))   

 On Sun, Jan 7, 2018 at 10:41 AM, Jani Tiainen  wrote:

> Hi,
>
> I didn't realize what you were asking for. :D
>
> Django has bunch of spatial queries, so you're looking some of those 
> __inside, __within lookups. Coordinate transformations do happen 
> automatically so you just need to provide srid for you "envelope".
>
> On Sun, Jan 7, 2018 at 1:48 AM, Tom Tanner  
> wrote:
>
>> Here's a sample PostGIS query I use to get geometries within four 
>> points:
>>
>> SELECT *
>> FROM myTable
>> WHERE ST_MakeEnvelope(-97.82381347656252, 30.250444940663296, -
>> 97.65901855468752, 30.29595835209862, 4326) && ST_Transform(myTable.
>> geom,4326);
>>
>>
>> With this query, I can get all rows within those four points. How do 
>> I execute this query or similar queries in Django or GeoDjango?
>>
>> -- 
>> You received this message because you are subscribed to the Google 
>> Groups "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, 
>> send an email to django-users...@googlegroups.com.
>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/aac95827-0c79-4aef-84cf-646ca82cfffa%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Jani Tiainen
>
> - Well planned is half done, and a half done has been sufficient 
> before...
>



 -- 
 Jani Tiainen

 - Well planned is half done, and a half done has been sufficient 
 before...

>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/67a80f04-1ea1-45b7-bfce-76863ae0f13e%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

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


Re: Managing a process from Django

2018-01-08 Thread Kasper Laudrup

Hi Joakim,

On 2018-01-08 22:50, Joakim Hove wrote:
Sounds to me that what you want is a `singleton` implemented in Python . 
The fact that Django is involved does not seem to be very relevant?




Indeed, that has crossed my mind and I'm sorry if this is in fact not 
very Django related. But I'm wondering if it would be a nice design to 
simply have a .py file with a singleton class and then accessing that 
from wherever I need it, but thinking about it, then why not?


Sorry if I have created a lot of noise, but that actually seems like 
exactly what I want. I might have been trying to overengineer things 
instead of just keeping it simple :-)


Thanks a lot for all the help from everyone helping me with my not very 
specific questions.


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 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/5e49dd7b-222a-782e-b50f-958b0e1a535c%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-08 Thread Kasper Laudrup

Hi Antonis,

On 2018-01-08 22:46, Antonis Christofides wrote:

OK, but why do you need this? What functionality is this going to have?



As I wrote in my original question, I'm attempting to write a Django 
application for managing DHCP leases and DNS entries.


So, if a user changes an entry by modifying a model in Django, I need to 
update some external files and restart a process so the new files will 
be reread.


I might be approaching this the wrong way, but I would really like my 
Django application to "own" this process, so I would like a global 
instance of that which I could start/restart/kill from my Django 
application.


I'm perfectly open for other ways to solve this, it just seemed like a 
fairly obvious way to do it, but I could very well be wrong.


Thanks a lot and 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 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/4b8dbfdc-27cf-2922-25c8-bf33f0dbf10e%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-08 Thread Joakim Hove
Sounds to me that what you want is a `singleton` implemented in Python .
The fact that Django is involved does not seem to be very relevant?


8. jan. 2018 22:43 skrev "Kasper Laudrup" :

> Hi Antonis,
>
> On 2018-01-08 22:10, Antonis Christofides wrote:
>
>> Hello,
>>
>> When you say "call [an instance of an object]", what exactly do you mean?
>>
>>
> Sorry, I meant an instance of a class or just an object.
>
> Could you tell us more about what this class/object is and why you need to
>> "call" (access?) it in an unusual way?
>>
>>
> Nothing unusual about the class or object, sorry about the confusion.
>
> My question is probably fairly simple and I'm really sorry if there's
> something very basic that I'm missing.
>
> I want to create an instance of some class when the Django application I'm
> creating is ready (eg. by connecting to the ready() signal or similar) and
> then be able to call methods on that single instance from my models.
>
> Thanks a lot for the help so far.
>
> 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 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/ms
> gid/django-users/bd87c994-77da-529b-1416-2e6d7a8d2aa5%40stacktrace.dk.
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Managing a process from Django

2018-01-08 Thread Antonis Christofides
OK, but why do you need this? What functionality is this going to have?

Antonis Christofides
http://djangodeployment.com

On 2018-01-08 23:43, Kasper Laudrup wrote:
> Hi Antonis,
>
> On 2018-01-08 22:10, Antonis Christofides wrote:
>> Hello,
>>
>> When you say "call [an instance of an object]", what exactly do you mean?
>>
>
> Sorry, I meant an instance of a class or just an object.
>
>> Could you tell us more about what this class/object is and why you need to
>> "call" (access?) it in an unusual way?
>>
>
> Nothing unusual about the class or object, sorry about the confusion.
>
> My question is probably fairly simple and I'm really sorry if there's
> something very basic that I'm missing.
>
> I want to create an instance of some class when the Django application I'm
> creating is ready (eg. by connecting to the ready() signal or similar) and
> then be able to call methods on that single instance from my models.
>
> Thanks a lot for the help so far.
>
> 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 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/aca7b60d-3aa5-a711-8ab1-cb36a538895a%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-08 Thread Kasper Laudrup

Hi Antonis,

On 2018-01-08 22:10, Antonis Christofides wrote:

Hello,

When you say "call [an instance of an object]", what exactly do you mean?



Sorry, I meant an instance of a class or just an object.


Could you tell us more about what this class/object is and why you need to
"call" (access?) it in an unusual way?



Nothing unusual about the class or object, sorry about the confusion.

My question is probably fairly simple and I'm really sorry if there's 
something very basic that I'm missing.


I want to create an instance of some class when the Django application 
I'm creating is ready (eg. by connecting to the ready() signal or 
similar) and then be able to call methods on that single instance from 
my models.


Thanks a lot for the help so far.

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 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/bd87c994-77da-529b-1416-2e6d7a8d2aa5%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-08 Thread Antonis Christofides
Hello,

When you say "call [an instance of an object]", what exactly do you mean?

Could you tell us more about what this class/object is and why you need to
"call" (access?) it in an unusual way?

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com


On 2018-01-08 22:02, Kasper Laudrup wrote:
> Hi again,
>
>>
>>     So my question is more related to any kind of process that should be
>>     managed from a Django app.
>>
>>
>> Django does not manages processes, Django is a web framework. Python can
>> manage processes. What kind? Any :)
>>
>
> I am fully aware of that, thank you :-)
>
> I guess my question is then actually more: if I would like to have one single
> instance of an object that I can call safely from models (or possibly views or
> whatever) where would be the right place to put that class and code?
>
> It seems like a fairly basic question, but I haven't found any obvious
> solution for that by reading the documentation, so maybe I'm just missing
> something basic? I must admit my experience with Django (although a good one)
> is fairly limited.
>
> Thanks a lot for your help so far.
>
> 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 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/374499b1-76b0-654a-92dd-e506523fc1a4%40djangodeployment.com.
For more options, visit https://groups.google.com/d/optout.


Upload file to a dynamically generated location

2018-01-08 Thread pieceofkayk2718
Hey Friends,

I'm having trouble figuring out how to upload a document model to a 
dynamically generated location.  The following models.py file contains two 
models and a helper function


views.py


# I would like the string inputs to be self.bundle.user, and 
self.bundle.name  where self is the document model.  I know this doesn't 
work which is why I am here asking this question.
def get_user_document_directory():
document_directory = 'media/{0}/{1}/documents/'.format( , _ ) 
return document_directory

class Bundle(models.Model):
user = models.ForeignKey(User)
name = models.CharField(max_length=100)

class Document(models.Model):
bundle = models.ForeignKey(Bundle)
name = models.CharField(max_length=100)
description = models.CharField(max_length=100)
document = models.FileField(upload_to=get_user_document_directory(self) 
) # I know passing self doesn't work but just trying to get the point 
across of what I am trying to do.
uploaded_at = models.DateTimeField(auto_now_add=True)



Any comments about how to remedy this situation would be greatly 
appreciated.  

Thanks,
K

-- 
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/71125202-9b89-4572-a086-ab9fed2b4d01%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-08 Thread Kasper Laudrup

Hi again,



So my question is more related to any kind of process that should be
managed from a Django app.


Django does not manages processes, Django is a web framework. Python can 
manage processes. What kind? Any :)




I am fully aware of that, thank you :-)

I guess my question is then actually more: if I would like to have one 
single instance of an object that I can call safely from models (or 
possibly views or whatever) where would be the right place to put that 
class and code?


It seems like a fairly basic question, but I haven't found any obvious 
solution for that by reading the documentation, so maybe I'm just 
missing something basic? I must admit my experience with Django 
(although a good one) is fairly limited.


Thanks a lot for your help so far.

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 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/d32507dc-3916-7cc3-10a9-8ea25926577d%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-08 Thread Ronnie Raney
Here's a view that works, in case someone in the future wants cares about 
this

def random_post(request):
post_count = Post.objects.all().count()  
random_val = random.randint(0, post_count-1)  
post_id = Post.objects.values_list('post_id', 
flat=True)[random_val]   
return redirect('post_detail', pk=post_id)

-- 
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/41d8a830-c76c-42f8-b475-929603fe052d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-08 Thread Matemática A3K
On Mon, Jan 8, 2018 at 2:51 PM, Ronnie Raney  wrote:

> *You can't change the of a user from a view unless you do a redirect. You
> can issue a redirect to /post/ where the id is what you picked at
> random at the "random_post" view*
>
> I can't change the *what *of a user from the view? Also, what user? I've
> tried putting  in there and it causes errors. I've also tried ,
> , , , and 
>
> *Is your template for a "random_obj" or for a "post" object? What does it
> expect? You can insert a "import ipdb; ipdb.set_trace()" after "context" in
> your view and inspect if it is right - it will probably be OK.*
> *Did you rename the post template to random_post and did not change the
> variables inside? If so, just use something like {"post": random_obj}.*
>
> The template is asking for the name of the url - "random_post". The
> template is loading right now at */post/random/* - confirmed by
> inspecting the page. The template expects to get the random_post view, I
> would assume. There are no errors telling me otherwise. Once again, the
> template is named random_post. So what I think you're suggesting is to
> change the contex to this:
>
> *context = {'random_obj':random_post,}*
>
> I also tried switching these:
>
> *context = {'random_post':random_obj,}*
>
> 'random_obj' is what was established here: *random_obj =
> Post.objects.get(post_id=random.choice(list(post_ids)))*
> 'random_post' is the name of my urlpattern, and the name of my template
> link
>
> Am I getting anywhere near understanding what you're saying? All of the
> things that I've tried are leading me to a template with blank fields.
>

Listen to Mattew's summary


> --
> 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/6e2224c1-ebbc-4f44-947b-a9115b56e4e8%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Managing a process from Django

2018-01-08 Thread Matemática A3K
On Mon, Jan 8, 2018 at 2:41 PM, Kasper Laudrup 
wrote:

> Hi Matemática A3K,
>
> On 2018-01-08 17:58, Matemática A3K wrote:
>
>>
>> With this https://stackoverflow.com/questions/89228/calling-an-externa
>> l-command-in-python
>> you can find out which distribution is using, then for each distribution
>> there's a different command for restarting DHCP (systemctl, upstart,
>> system-v) and with the same execute it with sudo to some user with
>> privileges to just do that. You can call that function ("restart_dhcp()")
>> from any django view.
>>
>>
> Thanks a lot for your answer.
>
> I would rather avoid using any kind of init system for managing dhcpd,
> since I would like to run the Django app in a docker container (running
> systemd inside docker is not a good idea) and the options given for eg.
> logging and configuration would be quite different from the standard
> installation of dhcpd on any distro.
>

Then it will be easier for you :)


>
> So my question is more related to any kind of process that should be
> managed from a Django app.
>
>
Django does not manages processes, Django is a web framework. Python can
manage processes. What kind? Any :)


> But thanks a lot for your input.
>
> 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 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/ms
> gid/django-users/8325b598-5db5-2a34-8fc5-aa4c1daf0ad5%40stacktrace.dk.
>
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-08 Thread Ronnie Raney
*You can't change the of a user from a view unless you do a redirect. You 
can issue a redirect to /post/ where the id is what you picked at 
random at the "random_post" view*

I can't change the *what *of a user from the view? Also, what user? I've 
tried putting  in there and it causes errors. I've also tried , 
, , , and 

*Is your template for a "random_obj" or for a "post" object? What does it 
expect? You can insert a "import ipdb; ipdb.set_trace()" after "context" in 
your view and inspect if it is right - it will probably be OK.*
*Did you rename the post template to random_post and did not change the 
variables inside? If so, just use something like {"post": random_obj}.*

The template is asking for the name of the url - "random_post". The 
template is loading right now at */post/random/* - confirmed by inspecting 
the page. The template expects to get the random_post view, I would assume. 
There are no errors telling me otherwise. Once again, the template is named 
random_post. So what I think you're suggesting is to change the contex to 
this:

*context = {'random_obj':random_post,}*

I also tried switching these:

*context = {'random_post':random_obj,}*

'random_obj' is what was established here: *random_obj = 
Post.objects.get(post_id=random.choice(list(post_ids)))*
'random_post' is the name of my urlpattern, and the name of my template link

Am I getting anywhere near understanding what you're saying? All of the 
things that I've tried are leading me to a template with blank fields.

-- 
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/6e2224c1-ebbc-4f44-947b-a9115b56e4e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-08 Thread matthew . pava
Check this out for how to redirect:
https://docs.djangoproject.com/en/2.0/topics/http/shortcuts/#redirect

Check this out for how Django determines the name of primary key fields:
https://docs.djangoproject.com/en/2.0/topics/db/models/#automatic-primary-key-fields

The best advice has already been provided: Get a random post id from your 
model and then redirect to the DetailView of that post.  You can figure it 
out.

On Monday, January 8, 2018 at 10:41:28 AM UTC-6, Ronnie Raney wrote:
>
> Please give me code. Sorry, I can't decipher plain language in forums very 
> well, when talking about code.
>
> My urlpattern:   
>
>  path('post//', views.PostDetailView.as_view(), 
> name='post_detail'),
>  path('post/*random*/*???*', views.random_post, name='random_post'),  *### 
> What do I put here?*
>
> My view:
>
> def random_post(request):
> post_ids = Post.objects.all().values_list('*post_id*', flat=True) * 
>  ### Is this correct? My field name is post_id - the primary key.*
> random_obj = Post.objects.get(*pk*=random.choice(post_ids))   *### 
> What do I put here? pk, id, post_id?*
> context = {'random_obj':random_obj,}
> return render(request, 'blog/random_post.html', context)
>
>>
>>

-- 
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/4834d44e-cb98-4d0d-b656-ff2c05a486a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Managing a process from Django

2018-01-08 Thread Kasper Laudrup

Hi Matemática A3K,

On 2018-01-08 17:58, Matemática A3K wrote:


With this 
https://stackoverflow.com/questions/89228/calling-an-external-command-in-python
you can find out which distribution is using, then for each distribution 
there's a different command for restarting DHCP (systemctl, upstart, 
system-v) and with the same execute it with sudo to some user with 
privileges to just do that. You can call that function 
("restart_dhcp()") from any django view.




Thanks a lot for your answer.

I would rather avoid using any kind of init system for managing dhcpd, 
since I would like to run the Django app in a docker container (running 
systemd inside docker is not a good idea) and the options given for eg. 
logging and configuration would be quite different from the standard 
installation of dhcpd on any distro.


So my question is more related to any kind of process that should be 
managed from a Django app.


But thanks a lot for your input.

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 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/8325b598-5db5-2a34-8fc5-aa4c1daf0ad5%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.


Re: urlopen error [Errno 110] Connection timed out

2018-01-08 Thread Julio Biason
Hello,

Where does this happen? Do you do urlopen somewhere? (IIRC, changing Django
settings doesn't affect internal Python objects).

urllib.request has a timeout, it's the second parameter after the data:
https://docs.python.org/3/library/urllib.request.html?highlight=urllib#urllib.request.urlopen

But you shouldn't do anything long while answering a request. You should
probalby use something like Celery to retrieve information in the
background, freeing the request (and later show the proper response).

On Mon, Jan 8, 2018 at 2:30 PM,  wrote:

>
> I use pythonanywhere. At this time, "urlopen error [Errno 110] Connection
> timed out" occurs. So I set CACHES TIMEOUT to None in Django settings.py.
> However, error 110 still occurs. Do I need to change the timeout value in
> urllib / request.py? I would really appreciate your help in this matter.
>
> --
> 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/2a798988-c7ab-4ec8-b967-e4f00af5b27b%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Julio Biason*, Sofware Engineer
*AZION*  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101   |  Mobile: +55 51
*99907 0554*

-- 
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/CAEM7gE2w3%2BCHPhhXdpohd1Y8t5ejjvE4Q_s%3DRt4XsOhAAuRSDQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-08 Thread Matemática A3K
On Mon, Jan 8, 2018 at 2:11 PM, Ronnie Raney  wrote:

> Thanks - for clarification. Yes! good advice on remaining calm. Apologies
> if I seemed intense.
>
> If I use this urlpattern, it takes me to the correct template.
>
> *path('post/random/', views.random_post, name='random_post'),*
>
> But there is no data. I really wanted to include the pk in the URL, to see
> which one it was picking at random.
>

You can't change the of a user from a view unless you do a redirect. You
can issue a redirect to /post/ where the id is what you picked at
random at the "random_post" view


> But it appears the data is not being queried correctly, or it's not being
> sent over as part of the view.
>
> Revised view:
>
> *def random_post(request):*
> *post_ids = Post.objects.all().values_list('post_id', flat=True)*
> *random_obj =
> Post.objects.get(post_id=random.choice(list(post_ids)))   I am still unsure
> if this is the correct variable. *
> *context = {'random_obj':random_obj,}*
> *return render(request, 'blog/random_post.html', context)*
>

Is your template for a "random_obj" or for a "post" object? What does it
expect? You can insert a "import ipdb; ipdb.set_trace()" after "context" in
your view and inspect if it is right - it will probably be OK.
Did you rename the post template to random_post and did not change the
variables inside? If so, just use something like {"post": random_obj}.

>
>
> Also, the here are my imports. Maybe there's something missing:
>
> *from django.shortcuts import render, redirect*
> *from .forms import ContactForm*
> *from django.http import HttpResponse, HttpResponseRedirect*
> *from django.shortcuts import render, redirect*
> *from django.core.mail import send_mail, BadHeaderError*
> *from django.http import HttpResponse, HttpResponseRedirect*
> *from django.utils import timezone*
> *from .models import Book, Writer, Translator, Post*
> *import random*
>
>
> --
> 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/7f118b95-c122-4fc3-bfee-f1d008919b5d%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

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


RE: Django 2.0.1 admin

2018-01-08 Thread Matthew Pava
I found the problem.  I had a third-party app, django-audit-log, that I 
incorporated into the project since it was not working with Django 2.0.  I 
needed to list ‘audit_log’ in the APPS list before django.contrib.admin in my 
Django settings module.

Problem solved!  Thank you!

From: Matthew Pava
Sent: Friday, January 5, 2018 4:27 PM
To: 'django-users@googlegroups.com'
Subject: RE: Django 2.0.1 admin

No.  I even uninstalled Django and reinstalled Django, but the issue persists.


From: django-users@googlegroups.com 
[mailto:django-users@googlegroups.com] On Behalf Of m1chael
Sent: Friday, January 5, 2018 4:25 PM
To: django-users@googlegroups.com
Subject: Re: Django 2.0.1 admin

did you ever override your admin templates?

On Fri, Jan 5, 2018 at 5:20 PM, Matthew Pava 
mailto:matthew.p...@iss.com>> wrote:
Hi everyone,
I am finally able to move to Django 2.0, but I just noticed an error I keep 
getting when attempting to open the admin:

TemplateSyntaxError at /admin/
Invalid block tag on line 58: 'get_admin_log', expected 'endblock'. Did you 
forget to register or load this tag?

Does anyone have any ideas?
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 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/4dbdb1ab1c37482eb2150fd8f6cd3426%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.

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

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


Re: Django local development server hangs after calling pandas df.plot a second time

2018-01-08 Thread Matemática A3K
On Mon, Jan 8, 2018 at 2:07 PM, asilver  wrote:

> I looked around for a django-pandas forum/group but could not find one...
>  I didnt' provide any errors or stack traces because there are none... The
> web server just hangs and I have to go into Windows task manager and kill
> the cmd window and sometime even that is not enough (I need to also
> separately kill the python2.7 process).  Any other recommendations for
> troubleshooting?  I'm not really a python expert by any means...
>
> Thx
>

Sorry, but I haven't used Pandas, django-pandas and I don't use Windows, so
I can't help you. Why don't you try opening an issue in
https://github.com/chrisdev/django-pandas or contacting the listed
contributors? I don't think they are reading this list...

HTH


>
>
> On Sunday, January 7, 2018 at 2:53:45 PM UTC-5, Matemática A3K wrote:
>>
>> Hi! This may be better suited for the django-pandas community, as it
>> involves its internals. It is also very hard to debug without errors or
>> stack traces.
>>
>> HTH
>>
>> On Sun, Jan 7, 2018 at 3:51 PM, asilver  wrote:
>>
>>> I'm trying to build a small website, using django, that stores network
>>> performance data. The user will be able to use filters to retrieve the
>>> exact data he/she wants and then have the option to graph that data. I'm
>>> using django-pandas to convert filtered queryset to a dataframe and from
>>> there to create a plot. Everything works fine the first time the plot
>>> function is called. When the plot function is called a second time, the
>>> python web server just hangs (started from python2.7.exe manage.py
>>> runserver).
>>>
>>> Here is the django view function:
>>>
>>>
>>> def FilteredPerformanceChartsView(request):
>>> f = PerfvRtrOnlyFilter(request.GET, queryset=PerfvRtrOnly.objects.all())
>>> df = read_frame(f.qs, fieldnames=['runDate', 'deviceName', 'aggrPPS', 
>>> 'jdmVersion'])
>>>
>>> #
>>> # Let's pass the Pandas DataFrame off to a seperate function for
>>> # further processing and to generate a chart.
>>> # This should return an image (png or jpeg)
>>> #
>>> chart = pandas_generate_chart(f.qs)
>>>
>>> return render(request,
>>>   'performance_charts.html',
>>>   context={'filter': f,
>>> 'chart': chart,
>>> 'dataFrame': df,
>>> },
>>>
>>>   )
>>>
>>>
>>>
>>> The function *pandas_generate_chart* is where the problem is. After
>>> performing a lot of troubleshooting, what appears to trigger the hang is
>>> calling df.plot a second time. In other words, when the user hits the
>>> button to generate a different chart. Until that second request to generate
>>> a chart is submitted, the website still works perfect. You will also notice
>>> that plt.close() is commented out below. If I uncomment that out, the
>>> webserver will hang the first time this function is called. (Note, it will
>>> display the chart). I've been looking into the pyplot interactive vs
>>> non-interactive modes to see if that was the cause of the problem. From the
>>> troubleshooting I've done, it is running in non-interactive mode.
>>>
>>>
>>> def pandas_generate_chart(filtered_queryset):
>>>
>>> df = read_frame(filtered_queryset, fieldnames=['jdmVersion', 
>>> 'hardware', 'deviceName', 'aggrPPS'])
>>> df = df.set_index('jdmVersion')
>>>
>>> # Plot
>>> myplot = df.plot(kind='barh', figsize=(12,7), grid=True)
>>> myplot.set_ylabel('JDM Version')
>>>
>>> format="png"
>>> sio_file = StringIO()
>>> plt.savefig(sio_file, format=format)
>>> image = base64.b64encode(sio_file.getvalue())#   plt.close()
>>> sio_file.close()
>>> return image
>>>
>>>
>>>
>>> Thank you for your help...
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/django-users/ed7e5391-3172-4914-bbd4-568e0f76d4f3%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

Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-08 Thread Ronnie Raney
Thanks - for clarification. Yes! good advice on remaining calm. Apologies 
if I seemed intense.

If I use this urlpattern, it takes me to the correct template.

*path('post/random/', views.random_post, name='random_post'),*

But there is no data. I really wanted to include the pk in the URL, to see 
which one it was picking at random. But it appears the data is not being 
queried correctly, or it's not being sent over as part of the view.

Revised view:

*def random_post(request):*
*post_ids = Post.objects.all().values_list('post_id', flat=True)*
*random_obj = 
Post.objects.get(post_id=random.choice(list(post_ids)))   I am still unsure 
if this is the correct variable. *
*context = {'random_obj':random_obj,}*
*return render(request, 'blog/random_post.html', context)*

Also, the here are my imports. Maybe there's something missing:

*from django.shortcuts import render, redirect*
*from .forms import ContactForm*
*from django.http import HttpResponse, HttpResponseRedirect*
*from django.shortcuts import render, redirect*
*from django.core.mail import send_mail, BadHeaderError*
*from django.http import HttpResponse, HttpResponseRedirect*
*from django.utils import timezone*
*from .models import Book, Writer, Translator, Post*
*import random*


-- 
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/7f118b95-c122-4fc3-bfee-f1d008919b5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Simple file uploading app

2018-01-08 Thread Matemática A3K
On Mon, Jan 8, 2018 at 9:16 AM, guettli  wrote:

> Just for the records: Since I found no matching solution I wrote a generic
> http upload tool: https://pypi.python.org/pypi/tbzuploader/
>
> For ftp there are thousands of clients, for automated upload via http I
> found none. That's why I wrote above tool.
>
> Regards,
>   Thomas
>

Good initiative! I think you didn't find anything because you might have
search it for Django and not for Python (but just a guess).
Here's one that can give you more ideas, like the progress bar:
https://github.com/tokland/youtube-upload

It's not generic enough for general use - at least to me - as for the
glance I took, it looks for pairs of files for your tbz site / software (I
don't know German), and I don't need an uploader, but I will have it in
mind :)


> Am Mittwoch, 25. Oktober 2017 16:57:31 UTC+2 schrieb guettli:
>>
>> I need a simple file uploading app.
>>
>> Every user should be able to upload files to his own area.
>>
>> This is the basic feature. You could think of additional goodies, but the
>> first step is
>> above feature.
>>
>> I tried to find an application which implements this, but failed.
>>
>> I tried this and other searches:
>>
>> https://djangopackages.org/search/?q=upload
>>
>>
>> Before I start coding, I wanted to ask here, because I prefer re-using to
>> re-inventing :-)
>>
>> Do you know an app which gives me this feature?
>>
>> Regards,
>>   Thomas Güttler
>>
>>
>> --
> 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/016f37e6-3d91-40bc-bef5-8da625125117%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Django local development server hangs after calling pandas df.plot a second time

2018-01-08 Thread asilver
I looked around for a django-pandas forum/group but could not find one...  
 I didnt' provide any errors or stack traces because there are none... The 
web server just hangs and I have to go into Windows task manager and kill 
the cmd window and sometime even that is not enough (I need to also 
separately kill the python2.7 process).  Any other recommendations for 
troubleshooting?  I'm not really a python expert by any means...

Thx


On Sunday, January 7, 2018 at 2:53:45 PM UTC-5, Matemática A3K wrote:
>
> Hi! This may be better suited for the django-pandas community, as it 
> involves its internals. It is also very hard to debug without errors or 
> stack traces.
>
> HTH
>
> On Sun, Jan 7, 2018 at 3:51 PM, asilver  > wrote:
>
>> I'm trying to build a small website, using django, that stores network 
>> performance data. The user will be able to use filters to retrieve the 
>> exact data he/she wants and then have the option to graph that data. I'm 
>> using django-pandas to convert filtered queryset to a dataframe and from 
>> there to create a plot. Everything works fine the first time the plot 
>> function is called. When the plot function is called a second time, the 
>> python web server just hangs (started from python2.7.exe manage.py 
>> runserver).
>>
>> Here is the django view function:
>>
>>
>> def FilteredPerformanceChartsView(request):
>> f = PerfvRtrOnlyFilter(request.GET, queryset=PerfvRtrOnly.objects.all())
>> df = read_frame(f.qs, fieldnames=['runDate', 'deviceName', 'aggrPPS', 
>> 'jdmVersion'])
>>
>> #
>> # Let's pass the Pandas DataFrame off to a seperate function for 
>> # further processing and to generate a chart.
>> # This should return an image (png or jpeg)
>> #
>> chart = pandas_generate_chart(f.qs)
>>
>> return render(request,
>>   'performance_charts.html',
>>   context={'filter': f,
>> 'chart': chart,
>> 'dataFrame': df,
>> },
>>
>>   )
>>
>>
>>
>> The function *pandas_generate_chart* is where the problem is. After 
>> performing a lot of troubleshooting, what appears to trigger the hang is 
>> calling df.plot a second time. In other words, when the user hits the 
>> button to generate a different chart. Until that second request to generate 
>> a chart is submitted, the website still works perfect. You will also notice 
>> that plt.close() is commented out below. If I uncomment that out, the 
>> webserver will hang the first time this function is called. (Note, it will 
>> display the chart). I've been looking into the pyplot interactive vs 
>> non-interactive modes to see if that was the cause of the problem. From the 
>> troubleshooting I've done, it is running in non-interactive mode.
>>
>>
>> def pandas_generate_chart(filtered_queryset):
>>
>> df = read_frame(filtered_queryset, fieldnames=['jdmVersion', 'hardware', 
>> 'deviceName', 'aggrPPS'])
>> df = df.set_index('jdmVersion')
>>
>> # Plot
>> myplot = df.plot(kind='barh', figsize=(12,7), grid=True)
>> myplot.set_ylabel('JDM Version')
>>
>> format="png"
>> sio_file = StringIO()
>> plt.savefig(sio_file, format=format)
>> image = base64.b64encode(sio_file.getvalue())#   plt.close()
>> sio_file.close()
>> return image
>>
>>
>>
>> Thank you for your help...
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/ed7e5391-3172-4914-bbd4-568e0f76d4f3%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

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


Re: Managing a process from Django

2018-01-08 Thread Matemática A3K
On Mon, Jan 8, 2018 at 12:48 PM, Kasper Laudrup 
wrote:

> Hi fellow Django users,
>
> I'm working on creating a Django application for managing DHCP leases and
> DNS entries and for that I would like to be able to (re)start the DHCP
> daemon from Djano.
>
> I think it would be best to simply use a popen object from pythons
> subprocess module (most likely wrapped in a class), but I'm not really sure
> which place would be the most logical place to keep that object? Of course
> there should only be a single instance of that object.
>
> I have also been looking into using some kind of service framework, but
> what I have found so far seems to be aimed at task queues (celery etc.),
> which would definitely be an overkill for my use case.
>
> It could also be that I'm approaching this the wrong way, in which case I
> would be happy to hear better ideas on how to do this.
>
> Thanks a lot for any input.
>
> Kind regards,
>
> Kasper Laudrup
>

With this
https://stackoverflow.com/questions/89228/calling-an-external-command-in-python
you can find out which distribution is using, then for each distribution
there's a different command for restarting DHCP (systemctl, upstart,
system-v) and with the same execute it with sudo to some user with
privileges to just do that. You can call that function ("restart_dhcp()")
from any django view.

HTH


>
> --
> 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/ms
> gid/django-users/f86f877c-3462-b8bd-95ac-3da1c77c8f72%40stacktrace.dk.
> For more options, visit https://groups.google.com/d/optout.
>

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


urlopen error [Errno 110] Connection timed out

2018-01-08 Thread suase9303

I use pythonanywhere. At this time, "urlopen error [Errno 110] Connection 
timed out" occurs. So I set CACHES TIMEOUT to None in Django settings.py. 
However, error 110 still occurs. Do I need to change the timeout value in 
urllib / request.py? I would really appreciate your help in this matter.

-- 
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/2a798988-c7ab-4ec8-b967-e4f00af5b27b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Managing a process from Django

2018-01-08 Thread Kasper Laudrup

Hi fellow Django users,

I'm working on creating a Django application for managing DHCP leases 
and DNS entries and for that I would like to be able to (re)start the 
DHCP daemon from Djano.


I think it would be best to simply use a popen object from pythons 
subprocess module (most likely wrapped in a class), but I'm not really 
sure which place would be the most logical place to keep that object? Of 
course there should only be a single instance of that object.


I have also been looking into using some kind of service framework, but 
what I have found so far seems to be aimed at task queues (celery etc.), 
which would definitely be an overkill for my use case.


It could also be that I'm approaching this the wrong way, in which case 
I would be happy to hear better ideas on how to do this.


Thanks a lot for any input.

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 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/f86f877c-3462-b8bd-95ac-3da1c77c8f72%40stacktrace.dk.
For more options, visit https://groups.google.com/d/optout.


How to filter choices in Django2's autocomplete_fields?

2018-01-08 Thread Oren


In Django 2.0, autocomplete_fields 

 was 
added, which is great.

Without autocomplete_fields, I can change the queryset of a ForeignKeyField 
using formfield_for_foreignkey 

.

But combining the two together doesn't work - it looks like the list of 
options for autocomplete is dynamic and coming from a different url, 
instead of from the current form.

So the question is -

How can I change the queryset in the autocomplete widget?
Thanks,
Oren

-- 
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/fd9c8a90-e1f8-47d1-af0a-a110a0b14846%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-08 Thread Matemática A3K
On Mon, Jan 8, 2018 at 1:37 PM, Ronnie Raney  wrote:

> Ugh. Sorry for the confusion. Here again are the pieces where I need
> suggestions. Please suggest actual code. I can't decipher things written in
> plain language on forums. Code is key for me.
>

OK, first, calm down, seems that your feelings aren't letting you think and
you are "running in circles". Code is a language, just as English, you can
understand both, you just need to read it slowly and calmed.


>
> path('post//', views.PostDetailView.as_view(),
> name='post_detail'),
>


> path('post/*random/???*', views.RandomDetailView.as_view(),
> name='random_post'),* ### I don't know what to put here*
>

No id and point it to the FBV:

> path('post/*random/*', views.random_post, name='random_post'),* ###
> I don't know what to put here*
>



>
>
> Also my view:
>
> def random_post(request):
> post_ids = Post.objects.all().values_list('post_id', flat=True)
>   * ### Is 'post_id' correct? YES That's my field name that is my primary
> key*
> random_obj = Post.objects.get(post_id=random.choice(list(post_ids)
> ))
> *### What do I put here? id? pk? post_id? -> You may have to convert the
> queryset to a list / evaluate but I'm not sure, you'll have to ty it*
> context = {'random_obj':random_obj,}
> return render(request, 'blog/random_post.html', context)
>
> I have tried a bunch of different configurations for my urlpattern. I have
> tried different variable names in my view. I'm not sure that my data is
> actually being inserted into my view. I don't know what my urlpattern is
> supposed to be. I don't know which variables to use in my view, regarding
> the primary key.
>

Calm down, yes you do, just re-read the thread slowly and you'll find the
answers :)


> --
> 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/d5ba26c4-dacc-4ad4-9050-55c1f44cdd8c%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-08 Thread Ronnie Raney
Please give me code. Sorry, I can't decipher plain language in forums very 
well, when talking about code.

My urlpattern:   

 path('post//', views.PostDetailView.as_view(), name='post_detail'),
 path('post/*random*/*???*', views.random_post, name='random_post'),  *### 
What do I put here?*

My view:

def random_post(request):
post_ids = Post.objects.all().values_list('*post_id*', flat=True) * 
 ### Is this correct? My field name is post_id - the primary key.*
random_obj = Post.objects.get(*pk*=random.choice(post_ids))   *### 
What do I put here? pk, id, post_id?*
context = {'random_obj':random_obj,}
return render(request, 'blog/random_post.html', context)

>
>

-- 
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/764fe76e-9d02-4c08-a4ae-f31346802a81%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-08 Thread Ronnie Raney
Ugh. Sorry for the confusion. Here again are the pieces where I need 
suggestions. Please suggest actual code. I can't decipher things written in 
plain language on forums. Code is key for me.

path('post//', views.PostDetailView.as_view(), 
name='post_detail'),
path('post/*random/???*', views.RandomDetailView.as_view(), 
name='random_post'),* ### I don't know what to put here*


Also my view:

def random_post(request):
post_ids = Post.objects.all().values_list('post_id', flat=True)* 
### 
Is 'post_id' correct? That's my field name that is my primary key*
random_obj = Post.objects.get(id=random.choice(post_ids))  *### 
What do I put here? id? pk? post_id?*
context = {'random_obj':random_obj,}
return render(request, 'blog/random_post.html', context)

I have tried a bunch of different configurations for my urlpattern. I have 
tried different variable names in my view. I'm not sure that my data is 
actually being inserted into my view. I don't know what my urlpattern is 
supposed to be. I don't know which variables to use in my view, regarding 
the primary key.

-- 
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/d5ba26c4-dacc-4ad4-9050-55c1f44cdd8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-08 Thread Matemática A3K
On Mon, Jan 8, 2018 at 11:50 AM, Ronnie Raney  wrote:

> Also, would something like this work, and would it be a way to create the
> view?
>

No, it won't work, you should read
https://docs.djangoproject.com/en/2.0/topics/class-based-views/intro/

>
> class RandomDetailView(DetailView):
> model = Post
> def random_post(request):
> post_ids = Post.objects.all().values_list('post_id', flat=True)
> random_obj = Post.objects.get(post_id=random.choice(post_ids))
> ###  Is "id" here supposed to be pk, or post_id?
> context = {'random_obj':random_obj,}
> return render(request, 'blog/random_post.html', context)
>
>
CBV have a standarized way of getting their object, "get_object()", you
have to override that method (or override the "get_queryset()") and make it
return your random post (which you already know). But also, you may need to
hack more the DetailView because it expects an id - and in the case of
random you won't have it, you are choosing the id at random.

Using a "lower level" CBV, like TemplateView may be easier, but if you
can't read
https://docs.djangoproject.com/en/2.0/topics/class-based-views/intro/
because of the hurry, a FBV will work and it's not a bad option :)


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

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


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-08 Thread Matemática A3K
On Mon, Jan 8, 2018 at 11:30 AM, Ronnie Raney  wrote:

> Thanks Mat-A3K
>
> Here's what I have so far...
>
> *models.py*
> class Post(models.Model):
> post_id = models.AutoField(primary_key=True)
>  all the other fields...
>
> *views.py*
>
> #Normal (not random) post detail view
> class PostDetailView(DetailView):
> model = Post
> template_name = 'blog/post_detail.html'
>
> # Random view
> def random_post(request):
> post_ids = Post.objects.all().values_list('post_id', flat=True)
> random_obj = Post.objects.get(id=random.choice(post_ids))
> context = {'random_obj':random_obj,}
> return render(request, 'blog/random_post.html', context)
>
> *urls.py*
>
> urlpatterns = [
> 
> path('post//', views.PostDetailView.as_view(),
> name='post_detail'), ### I included this to show my normal Post Detail view
> path('post//', views.random_post, name='random_post'),
> 
> ]
>
> The error I'm getting now has to do with template rendering. I am confused
> about what I should be using and where - id, post_id, pk, etc.
>
> Reverse for 'random_post' with no arguments not found. 1 pattern(s) tried: 
> ['post\\/random\\/(?P[0-9]+)\\/$']
>
>
> Please help me figure out my urlpattern, and corrections to my view. I think 
> we are very close!
>
>
You have the same url pointing to different views - 'post//' - in
what you pasted - that's a problem, in the best case only one will be used,
don't know which. On the other hand, the error is complaining that what it
could resolve has a non-optional id parameter - /post/random// -
which you are not passing (probably a "{% url 'random_post' %}"). Remove
the  from the pattern or add it to the url template tag if you need it.
And you probably need to clean up and fix your urls.py... :)


> --
> 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/176a1d46-d74e-4999-bb86-b90eac05882f%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-08 Thread Ronnie Raney
Also, would something like this work, and would it be a way to create the 
view?

class RandomDetailView(DetailView):
model = Post
def random_post(request):
post_ids = Post.objects.all().values_list('post_id', flat=True)
random_obj = Post.objects.get(id=random.choice(post_ids))  ###  Is 
"id" here supposed to be pk, or post_id? 
context = {'random_obj':random_obj,}
return render(request, 'blog/random_post.html', context)



-- 
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/e647327a-6f64-4cb1-a4fc-c5188db010ee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Select random blog post Object from "Post" Model and render In View/Template

2018-01-08 Thread Ronnie Raney
Thanks Mat-A3K

Here's what I have so far...

*models.py*
class Post(models.Model):
post_id = models.AutoField(primary_key=True)
 all the other fields...

*views.py*

#Normal (not random) post detail view
class PostDetailView(DetailView):
model = Post
template_name = 'blog/post_detail.html'

# Random view
def random_post(request):
post_ids = Post.objects.all().values_list('post_id', flat=True)
random_obj = Post.objects.get(id=random.choice(post_ids))
context = {'random_obj':random_obj,}
return render(request, 'blog/random_post.html', context)

*urls.py*

urlpatterns = [

path('post//', views.PostDetailView.as_view(), 
name='post_detail'), ### I included this to show my normal Post Detail view
path('post//', views.random_post, name='random_post'),

]

The error I'm getting now has to do with template rendering. I am confused 
about what I should be using and where - id, post_id, pk, etc.

Reverse for 'random_post' with no arguments not found. 1 pattern(s) tried: 
['post\\/random\\/(?P[0-9]+)\\/$']


Please help me figure out my urlpattern, and corrections to my view. I think we 
are very close!

-- 
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/176a1d46-d74e-4999-bb86-b90eac05882f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Simple file uploading app

2018-01-08 Thread guettli
Just for the records: Since I found no matching solution I wrote a generic 
http upload tool: https://pypi.python.org/pypi/tbzuploader/

For ftp there are thousands of clients, for automated upload via http I 
found none. That's why I wrote above tool.

Regards,
  Thomas

Am Mittwoch, 25. Oktober 2017 16:57:31 UTC+2 schrieb guettli:
>
> I need a simple file uploading app.
>
> Every user should be able to upload files to his own area.
>
> This is the basic feature. You could think of additional goodies, but the 
> first step is
> above feature.
>
> I tried to find an application which implements this, but failed.
>
> I tried this and other searches:
>
> https://djangopackages.org/search/?q=upload
>
>
> Before I start coding, I wanted to ask here, because I prefer re-using to 
> re-inventing :-)
>
> Do you know an app which gives me this feature?
>
> Regards,
>   Thomas Güttler
>
>
>

-- 
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/016f37e6-3d91-40bc-bef5-8da625125117%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.