I did it like this :

*in controller :*

def index():
    return locals()

def edit():
    response.flash = "Viewing All recordes For %s ." % (request.vars.table)

    # Get ALL Fields For a table Using Request.vars
    dbtable=db[request.vars.table]['fields']

    entries = db(db[request.vars.table].id >= 0).select()
    return locals()

def users():
     return locals()

def login():
    form=auth.login()
    return locals()

def download():
    """
    allows downloading of uploaded files
    http://..../[app]/default/download/[filename]
    """
    return response.download(request,db)


*in view:*

  <!-- Data -->
            <table class="table table-bordered table-striped table-hover" >

                <!-- Table Fields -->
                <thead>
                <tr>
                    {{fields = []}}
                  {{for i in dbtable:}}
                  <th style="text-align:center">{{=i}}</th>
                    {{fields.append(i)}}
                  {{pass}}
                  <th>Edit</th>
                  <th>Delete</th>
                </tr>
              </thead>
               <!-- End Of Table  Fields -->


                    {{number = 0}}
                {{for s in entries:}}
                    <tr>
                    {{for i in fields:}}
                        {{if db[request.vars.table][i].type == 'upload':}}
                        <td style="text-align:center"><img
src="{{=URL('download',args=s[i])}}" width="50px" height="150px"/></td>
                        {{else:}}
                        <td
style="text-align:center">{{=str(s[i])[:10]}}</td>
                        {{pass}}
                    {{pass}}
                        <td style="width:70px">
                            <form method="post"
action="{{=URL('editrecord')}}">
                                <input type="hidden" name="ID" value="{{=
s.id}}"/>
                                <input type="hidden" name="table"
value="{{=request.vars.table}}"/>
                        <button class="btn btn-success" type="submit"
style="width:70px" href="#"><i class="icon-cog"></i> Edit</button>
                            </form>
                        </td>
                        <td style="width:90px">
                        <form method="post"
action="{{=URL('deleterecord')}}">
                                <input type="hidden" name="ID" value="{{=
s.id}}"/>
                                <input type="hidden" name="table"
value="{{=request.vars.table}}"/>
                        <button class="btn btn-danger" type="submit"
style="width:90px"><i class="icon-remove"></i> Delete</button>
                            </form>
                        </td>


                    {{number = number + 1}}
                   </tr>
                {{pass}}

               <tbody>
                </tbody>
</table>


Best Regards,



On Tue, Dec 11, 2012 at 5:36 PM, tomasz bandura <tomasz.band...@gmail.com>wrote:

> Ok,
>
> To complete my example: You should define two tables (db.py)
>
> db.define_table('tag',Field('name',length=16),format='%(name)s')
> db.define_table('entry',
>  Field('title',length=64),
>         # (...) some other fields
> Field('tags','list:reference tag'))
>
>
>
> 2012/12/11 hasan alnator <halna...@gardeniatelco.com>
>
>> <type 'exceptions.AttributeError'> 'DAL' object has no attribute 
>> 'entry'VERSION
>> web2py™ (2, 1, 1, datetime.datetime(2012, 10, 15, 12, 44, 40), 
>> 'stable')PythonPython
>> 2.7.3: C:\Python27\python.exe TRACEBACK
>>
>> 1.
>> 2.
>> 3.
>> 4.
>> 5.
>> 6.
>> 7.
>> 8.
>> 9.
>> 10.
>> 11.
>> 12.
>>
>> Traceback (most recent call last):
>>   File "C:\web2py\gluon\restricted.py", line 209, in restricted
>>
>>
>>     exec ccode in environment
>>   File "C:/web2py/applications/A3rasna_latestshop/controllers/admin.py" 
>> <http://127.0.0.1:8000/admin/default/edit/A3rasna_latestshop/controllers/admin.py>,
>>  line 22, in <module>
>>
>>
>>   File "C:\web2py\gluon\globals.py", line 187, in <lambda>
>>
>>
>>     self._caller = lambda f: f()
>>
>>
>>   File "C:/web2py/applications/A3rasna_latestshop/controllers/admin.py" 
>> <http://127.0.0.1:8000/admin/default/edit/A3rasna_latestshop/controllers/admin.py>,
>>  line 12, in edit
>>
>>
>>     entries = 
>> db(db.entry.tags.contains(request.vars.table)).select(db.entry.ALL)
>>
>>
>>   File "C:\web2py\gluon\dal.py", line 7150, in __getattr__
>>
>>
>>     return ogetattr(self, key)
>>
>> AttributeError: 'DAL' object has no attribute 'entry'
>>
>>   --
>>
>>
>>
>>
>
>  --
>
>
>
>

-- 



Reply via email to