Django application to extract data from other application models?

I have synchronization of the name of the application, which has a form created from a model that saves itself. I want to create another application called activity that extracts data from synchronization models and other future applications. How to do this in the application activities?

This is my sync models.py

from django.db import models
from django.contrib.auth.models import User
from django.forms import ModelForm

FS_CHOICES = (
    ('/path1/', 'P1'),
    ('/path2/', 'P2'),
    ('/path3/', 'P3'),
)

OPTIONS = (
    ('-n', 'TRY'),
)


class SyncJob(models.Model):
  date = models.DateTimeField()
  user = models.ForeignKey(User, unique=False)
  source = models.CharField(max_length=3, choices=FS_CHOICES)
  destination = models.CharField(max_length=3, choices=FS_CHOICES)
  options = models.CharField(max_length=10, choices=OPTIONS)

class SyncJobForm(ModelForm):
  class Meta:
    model = SyncJob
    fields = ['source', 'destination', 'options'] 

Ok, in activity views.py I have this:

from toolbox.sync.models import SyncJob
from django.shortcuts import render_to_response

def Activity()
   sync_job = SyncJob.objects.get(id=03)

   return render_to_response('base.html', {'sync_job': sync_job})

UPDATE: when I try to view the page, it displays an error: The 'function' object is not iterable

+3
source share
1 answer

Just import it like any other python class.

, - :

from sync.models import SyncJob
sync_job = SyncJob.objects.get(id=99)
+5

Source: https://habr.com/ru/post/1759813/


All Articles