asifpy / django-crudbuilder

Generic CRUD implementation in Django
https://django-crudbuilder.readthedocs.org/en/latest/index.html
Apache License 2.0
193 stars 67 forks source link

type object 'inventoryCrud' has no attribute 'search_feilds' #20

Closed andy2046 closed 8 years ago

andy2046 commented 8 years ago

pls help to check the issue below:

class inventoryInlineFormset(BaseInlineFormset):
        inline_model = OS
        parent_model = inventory
        extra = 1
        can_delete = True
        fk_name = 'inventory'
        #exclude = ['created_by', 'updated_by']
        #formset_class = YourBaseInlineFormset
        #child_form = ChildModelForm

class inventoryCrud(BaseCrudBuilder):
    model = inventory
    custom_modelform = inventoryForm
    search_fields = ['appcode','hostname','alias','env']
    tables2_fields = ('appcode','appcode_desc','hostname','alias','env','tier','hardware_platform','hardware_model')
    tables2_css_class = "table table-bordered table-condensed"
    tables2_pagination = 20  # default is 10
    #modelform_excludes = ['created_by', 'updated_by']
    login_required=False
    permission_required=False
    inlineformset = inventoryInlineFormset

class OSCrud(BaseCrudBuilder):
    model = OS
    search_fields = ['OS_name','OS_current_version','OS_patch_level','OS_EOS_status','OS_EOS_date']
    tables2_fields = ('OS_name','OS_current_version','OS_patch_level','OS_EOS_status','OS_EOS_date')
    tables2_css_class = "table table-bordered table-condensed"
    tables2_pagination = 20  # default is 10
    #modelform_excludes = ['created_by', 'updated_by']
    login_required=True
    permission_required=False

1: type object 'inventoryCrud' has no attribute 'search_feilds' when I serach

2: 'ForeignKey' object has no attribute 'get_forward_related_filter' when I click to go to detail page

3: if I have one more child model DB for inventory, how to add 2 models to inline formset

inline_model = (OS,DB) doesnot work

thanks

asifpy commented 8 years ago
  1. Which version of crudbuilder are you using? Can you please test with latest revision (0.2.2)
  2. Can you please share your parent child models for further investigation.
  3. Currently crudbuilder doesn't support nested inline formset
andy2046 commented 8 years ago

Hi asifpy,

I installed the latest version 0.2.2,

1: got another issue when search:

TypeError at /incident/crud/bd_incident/inventories/
Related Field got invalid lookup: icontains
Request Method: GET
Request URL:    http://localhost:8999/incident/crud/bd_incident/inventories/?search=A
Django Version: 1.8.6
Exception Type: TypeError
Exception Value:    
Related Field got invalid lookup: icontains
Exception Location: ...\Anaconda2\lib\site-packages\django\db\models\fields\related.py in get_lookup_constraint, line 1764

...\Anaconda2\lib\site-packages\crudbuilder\mixins.py in dispatch
                        request, *args, **kwargs) 

2: I have one inventory model which is parent and 2 child models OS and DB

class inventory(models.Model):    
    appcode = models.ForeignKey(Applicationin, to_field='code', max_length=10,null=False, blank=False)
    appcode_desc=models.CharField(max_length=100,blank=True, null=True)
    hostname=models.CharField(max_length=50,null=False, blank=False)
    alias =models.CharField(max_length=200,blank=True, null=True)
    env=models.CharField(max_length = 10, choices = env_list,null=False, blank=False)

    class Meta:
        ordering = ('appcode',)
        unique_together = (('appcode','hostname','env'),)

    def __unicode__(self):
        return "%s-%s-%s" % (self.appcode.code, self.env, self.hostname) or u''

class OS(models.Model):
    OS_name=models.CharField(max_length=100,blank=False, null=False)
    OS_current_version=models.CharField(max_length=100,blank=True, null=True)
    inventory = models.ForeignKey(inventory, on_delete=models.CASCADE)

    def __unicode__(self):
        return "%s" % self.OS_name or u'' 

class DB(models.Model):
    instance_name=models.CharField(max_length=30,blank=True, null=True)
    DB_current_version=models.CharField(max_length=100,blank=True, null=True)
    inventory = models.ForeignKey(inventory, on_delete=models.CASCADE)

    def __unicode__(self):
        return "%s" % self.instance_name or u'' 

3: can I add 2 child models to inline formset so one inventory form include 2 inline form set for OS and DB? inline_model = (OS,DB) doesnot work

any plan to support this?

Thanks.

andy2046 commented 8 years ago

To add on details for details page issue

AttributeError at /incident/crud/bd_incident/inventories/2/
'ForeignKey' object has no attribute 'get_forward_related_filter'
Request Method: GET
Request URL:    http://localhost:8999/incident/crud/bd_incident/inventories/2/
Django Version: 1.8.6
Exception Type: AttributeError
Exception Value:    
'ForeignKey' object has no attribute 'get_forward_related_filter'
Exception Location: ..\Anaconda2\lib\site-packages\crudbuilder\templatetags\tags.py in inline_objects, line 69
asifpy commented 8 years ago

OK. I used the same models which you posted above and tested crud functionality. Below are my findings:

  1. Be specific about the search field which you want to search. In your case you are trying to search FK field appcode, instead of using appcode, use appcode__code in search_fields list where code is the search item. (You need to span your relation to specific search fields). You can find similar case in example project. example/crud.py LINE 45.
  2. Regarding the detail page error, the error is when I use Django 1.8.6. Where as I cannot able to reproduce the same error using Django 1.9. I will fix that one for Django 1.8.6 (For now you can use Django 1.9 which will not raise such error)
  3. Currently I don't have any plans to add nested inline formset support. I have other things to finish for this crudbuider. In future definitely will add support for nested inline formset
andy2046 commented 8 years ago

Hi Asifpy,

For the detail page error, any temp solution if I do not upgrade from Django 1.8 to 1.9? Becoz I have to use 1.8 for a while before upgrading to 1.9, thanks.

asifpy commented 8 years ago

I fixed it for 1.8 also here https://github.com/asifpy/django-crudbuilder/commit/293404dc138006028e7c1b675e0d8d4bf98bca8a.

andy2046 commented 8 years ago

Noted, thanks a lot, will test again