I'm building an import excel files system for every leads whit import 
export library. In the Website each user must be able to import his leads 
and make sure that they are viewed only by him. In all other cases I 
filtered the "organisation" field linked to a UserProfile model through the 
views.py. But now I don't know how to filter the field organisation for a 
specific user.At the moment I can import the excel files from the template 
but leaving the organisation field blank. Help me please I'm desperate

Models.py
class Lead(models.Model): 
nome = models.CharField(max_length=20)
 cognome = models.CharField(max_length=20)
 luogo=models.CharField(max_length=50, blank=True, null=True, 
choices=region_list) città=models.CharField(max_length=20) email = 
models.EmailField() 
phone_number = models.CharField(max_length=20)
 description = models.TextField() 
 agent = models.ForeignKey("Agent", null=True, blank=True, 
on_delete=models.SET_NULL) 
category = models.ForeignKey("Category", related_name="leads", null=True, 
blank=True, on_delete=models.SET_NULL) 
chance=models.ForeignKey("Chance",related_name="chance", null=True, 
blank=True, on_delete=models.CASCADE) 
profile_picture = models.ImageField(null=True, blank=True, 
upload_to="profile_pictures/") converted_date = 
models.DateTimeField(null=True, blank=True) 
date_added = models.DateTimeField(auto_now_add=True) 
organisation = models.ForeignKey(UserProfile, 
on_delete=models.CASCADE,null=True, blank=True) 
 objects = LeadManager() 
age = models.IntegerField(default=0) def __str__(self): return 
f"{self.nome} {self.cognome}" 
 class User(AbstractUser): 
is_organisor = models.BooleanField(default=True)
 is_agent = models.BooleanField(default=False)
 class UserProfile(models.Model): 
  user = models.OneToOneField(User, on_delete=models.CASCADE)
 def __str__(self): return self.user.username

Views.py
def simple_upload(request):
  if request.method == 'POST': 
 Lead_resource = LeadResource()
 dataset = Dataset() 
 newdoc = request.FILES['myfile'] 
 imported_data = dataset.load(newdoc.read(),format='xlsx') 
  #print(imported_data) 
  for data in imported_data: 
 value = Lead( data[0], data[2],#nome data[3],#cognome data[5],#luogo 
data[7],#città data[8],#email data[9],#numero telefono data[11],#desc ) 
value.save() 
 result = Lead_resource.import_data(dataset, dry_run=True) # Test the data 
import if not result.has_errors(): 
 Lead_resource.import_data(dataset,dry_run=False) # Actually import now 
return render(request, 'input.html')

Resources.py
class LeadResource(resources.ModelResource):
 nome = fields.Field(attribute='nome', column_name='nome') 
luogo = fields.Field(attribute='luogo', column_name='regione') 
  class Meta:
  model = Lead report_skipped=True 

admin.py
@admin.register(Lead)
class PersonAdmin(ImportExportModelAdmin): 
 readonly_fields = ('date_added',)

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

Reply via email to